forked from vimukthi-git/howtocodebetterfaster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (33 loc) · 801 Bytes
/
app.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
'use strict';
const compress = require('koa-compress');
const logger = require('koa-logger');
const serve = require('koa-static');
const router = require('./router');
const koa = require('koa');
const path = require('path');
const conf = require('./config.json');
const app = module.exports = koa();
// pass the configs
let config = {};
if (process.env.APP_ENV === 'dev') {
config = conf.dev;
} else if (process.env.APP_ENV === 'prod') {
config = conf.prod;
} else {
config = conf.local;
}
// Logger
app.use(logger());
app.use(function* (next){
this.config = config;
yield next;
});
router(app);
// Serve static files
app.use(serve(path.join(__dirname, 'public')));
// Compress
app.use(compress());
if (!module.parent) {
app.listen(3000);
console.log('listening on port 3000');
}