0.0.3 • Published 11 years ago
mountain-js v0.0.3
mountain
Simple routing for Koa
Install
npm install mountain-jsUsage
const route = require("mountain-js");Examples
let app = koa();
app.use(route("GET", "/posts", function *(next) {
this.body = "got posts!";
}));
app.listen();Allow route on all methods.
app.use(route("/posts", function *(next) {
this.body = "always got posts!";
}));Param'd URLs.
app.use(route("GET", "/posts/:id", function *(next) {
this.body = "got post #" + this.params.id;
}));More middlewares.
let myMiddleware = function *(next) {
yield next;
}
app.use(route("POST", "/posts", myMiddleware, koaBody(), function *(next) {
this.body = "posted to posts";
}));Jump back out to the app from the routed middlewares
app.use(route("GET", "/posts", function *(next) {
this.body = "posted to posts";
yield next;
}));
app.use(function *(next) {
// hello!
});License
MIT
