Last active
October 10, 2017 13:41
-
-
Save isabellachen/7e50c694dffcffa1b2ca7085c4a998bb to your computer and use it in GitHub Desktop.
Bootstrap Koa Server index.js
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
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