-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (24 loc) · 667 Bytes
/
index.js
File metadata and controls
31 lines (24 loc) · 667 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
import Koa from 'koa'
import koaStatic from 'koa-static'
// import axios from 'axios'
import fs from 'fs'
const app = new Koa();
app.use(async (ctx, next) => {
await next();
const rt = ctx.response.get('X-Response-Time');
console.log(`${ctx.method} ${ctx.ip} ${ctx.url} - ${rt}`);
});
app.use(async (ctx, next) => {
const start = Date.now();
await next();
const ms = Date.now() - start;
ctx.set('X-Response-Time', `${ms}ms`);
});
app.use(koaStatic('public'));
app.use(async ctx => {
if(ctx.request.URL.pathname === "/planes") {
ctx.body = fs.readdirSync('public/planesData');
}
});
const PORT = process.env.PORT || 3000;
app.listen(PORT);