-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (34 loc) · 958 Bytes
/
server.js
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
37
38
39
40
41
42
43
44
45
46
47
48
const Koa = require('koa');
const path = require('path');
const Router = require('@koa/router');
const koaSimpleHealthCheck = require('koa-simple-healthcheck');
const sendfile = require('koa-sendfile');
const koaLogger = require('koa-logger');
const bunyan = require('bunyan');
const streams = [
{
stream: process.stdout,
level: process.env.LOGGER_LEVEL || 'debug'
}, {
stream: process.stderr,
level: 'warn'
},
];
const logger = bunyan.createLogger({
name: 'rw-lp',
src: true,
streams,
});
const router = new Router({});
const app = new Koa();
app.use(koaLogger());
app.use(koaSimpleHealthCheck());
router.get('/', (ctx) => {
sendfile(ctx, path.join(`${__dirname}/dist/index.html`));
});
app.use(require('koa-static')('dist'));
const port = process.env.PORT || 8080;
const server = app.listen(port, () => {
logger.info(`Server listening at ${port}`);
});
module.exports = server;