Skip to content

Instantly share code, notes, and snippets.

@isabellachen
Last active October 10, 2017 13:41
Show Gist options
  • Save isabellachen/7e50c694dffcffa1b2ca7085c4a998bb to your computer and use it in GitHub Desktop.
Save isabellachen/7e50c694dffcffa1b2ca7085c4a998bb to your computer and use it in GitHub Desktop.
Bootstrap Koa Server index.js
const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const cors = require('kcors');
const Console = console;
const app = new Koa();
const router = require('./router');
const db = require('./db');
app
.use(async (cxt, next) => {
try {
await next();
} catch (e) {
ctx.status = 500;
if (e.message) {
ctx.body = {
errors: [e.message]
};
}
}
})
.use(bodyParser())
.use(cors())
.use(router.routes())
.use(router.allowedMethods());
app.listen(3000, ()=> {
Console.log('koa app listening on port 3000');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment