0.2.1 • Published 10 years ago

koa-mount-dir v0.2.1

Weekly downloads
1
License
MIT
Repository
github
Last release
10 years ago

Simple routing lib for Koa based on this code.

Installation

$ npm install koa-mount-dir

Example

File structure:

- api
  - users
    - config.json
    - index.js
- pages
  - home
    - config.json
    - index.js
- app.js

In config.json:

{
    "routes": {
        "GET /path/to/": "detail"
    }
}

Where "GET /path/to/" is http method with routing path and "detail" is handler name witch exports in index.js

index.js source:

exports.detail = function *() { this.body = 'ok' }

app.js source:

var koa = require('koa');
var app = koa();

var mountPages = require('koa-mount-dir')('pages');

// first argument "api" is path to mount dir and second argument is prefix to path ('/users/' -> /api/v1/users/)
var mountApi = require('koa-mount-dir')('api', '/api/v1');

// for mount ./api dir with path prefix "/api/v1"
mountApi(app);

// for mount ./pages dir
mountPages(app);

app.listen(8000);

For running example

$ make example

Running tests

$ make test

Authors

License

MIT

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.1

10 years ago

0.0.0

10 years ago