forked from PDIS/CastingWords
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (26 loc) · 727 Bytes
/
server.js
File metadata and controls
35 lines (26 loc) · 727 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
const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const app = new Koa();
const path = require('path');
const render = require('koa-ejs');
render(app, {
root: path.join(__dirname, 'view'),
layout: 'template',
viewExt: 'html',
cache: false,
debug: false
});
app.use(bodyParser());
app.use(async (ctx, next) => {
await next();
const rt = ctx.response.get('X-Response-Time');
console.log(`${ctx.method} ${ctx.url} - ${rt}`);
});
app.use(require('koa-static')('transcript', {}));
const apiRoute = require('./router/route.js').route;
app.use(apiRoute.middleware());
const server = require('http').createServer(app.callback());
server.listen(3000);
module.exports = {
app, server
};