Last active
November 18, 2015 16:13
-
-
Save NikolayGalkin/a38ce7d2744d0c065e59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// run via: node server.js | |
'use strict'; | |
require('babel-core/register'); | |
require('babel-polyfill'); | |
const app = require('./app'); | |
app.listen(3000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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