-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (27 loc) · 788 Bytes
/
app.js
File metadata and controls
35 lines (27 loc) · 788 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
process.on('unhandledRejection', r => console.error(r));
const Koa = require('koa');
const ejs = require('koa-ejs');
const path = require('path');
const app = new Koa();
const port = 7001;
app.use(async (ctx, next) => {
const start = Date.now();
await next();
const ms = Date.now() - start;
console.log(`>> ${new Date(start).toISOString()} ${ctx.method} ${ctx.url} - ${ms}`);
});
app.use(require('koa-static')('public'));
ejs(app, {
root: path.join(__dirname, 'views'),
viewExt: 'ejs',
});
app.use(function (ctx, next) {
ctx.state = ctx.state || {};
return next();
});
app.use(require('./routes/index').routes());
app.listen(port);
console.log(`Open http://localhost:${port} in the browser.`);
app.on('error', function (err) {
console.error(err, err.stack);
});