1.3.32 • Published 9 years ago
@recipher/server v1.3.32
@recipher/server
Server is a koa.js web server with sane defaults.
Usage
var Server = require('@recipher/server');
var server = new Server();
// To configure routes and middleware
server.configure('/path/to/apps');
// To start
server.start();
// To stop
server.stop();Resources
Resource files are expected in a specific structure:
apps
users
resources
routes.js
users.js
user.js
groups
resources
routes.js
groups.js
group.jsThis will mount routes at /users and /groups, if the apps folder is passed to server.configure.
The routes.js file should export a single function, passed with these parameters:
module.exports = function(router, resources, errors) {
//
};The router parameter is a koa-router, the resources is an array of all of the files in the directory, each of which should have route handlers.
For example, users.js should export a function which returns multiple handlers:
module.exports = function(errors) {
return {
get: function *(next) { }
, post: function *(next) { }
}
};And these would be routed in routes.js like this:
module.exports = function(router, resources, errors) {
var users = resources.users(errors);
router.get('/', users.get);
router.post('/', users.post);
};