
# Yoo

  ![kangaroo](https://cldup.com/X4VwDx3Mlx.png)

  Jump-start your front-end server. Bundles and configures the boilerplate of a Koa app.

  Originally inspired by [tj/serve](https://github.com/tj/serve).
  Then inspired by [lapwinglabs/roo](https://github.com/lapwinglabs/roo).

## Goal

Similar to how Heroku ushers you towards the [Twelve-Factor App](http://12factor.net/),
the goal of Yoo is to provide smart defaults for quickly building front-end servers,
while keeping the library small and configurable.

As the server landscape changes, we'll be adding and removing features. We will
increment the major version each time we make these sorts of changes.

Some ideas of features we're currently considering:

- Express middleware support using [http-context](https://github.com/lapwinglabs/http-context).
- Configurable logging using [bole](https://github.com/rvagg/bole).
- Pluggable message queues to encourage stateless servers.
- Multipart support
- BrowserSync / LiveReload support

## Installation

Using the API:

```bash
npm install yoo
```

## Features

  * Flexible: Javascript
  * Deployable: Ready to be deployed to Dokku or Heroku
  * Composable: Mount Koa servers within or mount within other Koa servers.
  * Higher-level: Templating, Routing & Asset Bundling baked-in

## Example

**API:**

```js
Yoo(__dirname)
  .auth('username', 'password')
  .get('/', 'index.jade')
  .exec('make build')
  .mount('/api', api)
  .compress()
  .serve('build')
  .cors()
  .listen(4000);
```

## API

##### `Yoo(root)`

Initialize `Yoo` at the `root` path. Defaults to `.`.

##### `Yoo.{get,post,put,delete,...}(route[, middleware, ...], handle)`

Add a route to `Yoo`. Routing is powered by [kr](https://github.com/lapwinglabs/kr), so visit there for API details.

Additionally, you may pass a `filepath` to `handle`, which will render using [consolidate](https://github.com/tj/consolidate.js).

```js
yoo
  .get('/', 'index.jade')
  .post('/signup', signup)
```

##### `Yoo.favicon(path)`

Set a favicon at `path`

##### `Yoo.auth(user, pass)`

Add basic auth with a `user` and `pass`.

##### `Yoo.logger([fn])`

Add route logging with an optional filter `fn`.

```js
yoo.logger(function(ctx) {
  return extname(ctx.url) ? false : true;
});
```

`ctx` in this case is a "koa context".

##### `Yoo.exec(command)`

Execute a `command` every refresh

##### `Yoo.use(generator)`

Pass additional middleware `generator`'s to `Yoo`.

##### `Yoo.mount(path)`

Mount inside another app at `path`.

```js
app.use(yoo.mount('/dashboard'));
```

##### `Yoo.mount(path, app)`

Mount an app inside of `Yoo` at `path`

```js
yoo.mount('/dashboard', app);
```

##### `Yoo.compress()`

Compress CSS and JS assets.

##### `Yoo.directory()`

Yoo the entire directory using [koa-serve-index](https://github.com/yiminghe/koa-serve-index)

##### `Yoo.static(directory)`

Add a static asset `directory` to yoo from

##### `Yoo.cors([options])`

Enable `CORS` on the yoo. `options` get passed directly to [node-cors](https://github.com/troygoode/node-cors/).

##### `Yoo.listen(port, fn)`

Start the server on `port`. You may pass the environment variable `PORT=8080` in to specify a port. Otherwise it defaults to `3000` if otherwise not specified.

## Test

```
npm install
make test
```

## Why Yoo?

Yoo is short for Kangaroo. I wrote this while visiting Australia for [CampJS](http://campjs.com) and I have Kangaroos on my mind.

## Credits

Kangaroo Icon by [Olivier Guin](http://thenounproject.com/olivierguin)

## License

(The MIT License)

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
