forked from maisieccino/ucl-assistant-notifications
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (28 loc) · 810 Bytes
/
server.js
File metadata and controls
36 lines (28 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const Koa = require("koa");
const bodyParser = require("koa-bodyparser");
const logger = require("koa-logger");
const objection = require("objection");
const Knex = require("knex");
const Raven = require("raven");
const router = require("./router");
const knexConfig = require("./knexfile");
require("dotenv").config();
Raven.config().install();
const app = new Koa();
app.use(logger());
const knex = Knex(knexConfig);
objection.Model.knex(knex);
app.use(bodyParser());
app.use(async (ctx, next) => {
try {
await next();
ctx.body = { content: ctx.response.body, error: "" };
} catch (error) {
ctx.body = { error: error.message || "An error occured" };
}
});
app.use(router.routes());
app.use(router.allowedMethods());
Raven.context(() => {
app.listen(process.env.PORT || 3000);
});