Skip to content

Instantly share code, notes, and snippets.

@NikolayGalkin
Last active November 18, 2015 16:13
Show Gist options
  • Save NikolayGalkin/a38ce7d2744d0c065e59 to your computer and use it in GitHub Desktop.
Save NikolayGalkin/a38ce7d2744d0c065e59 to your computer and use it in GitHub Desktop.
// run via: babel-node app.js
'use strict';
import Koa from 'koa';
import route from 'koa-route';
import {Users} from './controllers/users'
export const app = module.exports = new Koa();
app.use(route.get('/users', Users.list));
app.use(route.get('/users/:id', Users.detail));
if (!module.parent) {
app.listen(3000, function() {
console.log('Listen on: 3000');
});
}
// run via: node server.js
'use strict';
require('babel-core/register');
require('babel-polyfill');
const app = require('./app');
app.listen(3000);
'use strict';
export class Users {
static list(ctx) {
ctx.body = 'users list';
}
static async detail(ctx, id, next) {
await next();
ctx.body = id;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment