-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (27 loc) · 857 Bytes
/
index.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
const path = require('path');
const Koa = require('koa');
const serve = require('koa-static');
const favicon = require('koa-favicon');
const requestMw = require('./middleware/request.js');
const PORT = process.env.port || 8080;
const app = new Koa();
app.use(favicon(`${__dirname}/app/static/favicon.ico`));
if (process.env.NODE_ENV === 'production') {
app.use(serve(path.join(__dirname, 'public')));
}
app.use(requestMw);
/* eslint-disable no-console */
const server = app
.listen(PORT, () => {
console.log(`Koa server listening on port ${server.address().port}`);
})
.on('error', (err) => {
if (err.code === 'EACCES') {
console.log(`Error: port ${PORT} is already in use. Choose another one.`);
} else {
console.log('Error: ', err);
}
process.exit(1);
});
/* eslint-enable no-console */
module.exports = app;