-
Notifications
You must be signed in to change notification settings - Fork 58
/
app.js
45 lines (37 loc) · 1022 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
41
42
43
44
45
'use strict';
var app = require('koa')(),
logger = require('koa-logger'),
serve = require('koa-static'),
router = require('koa-router')(),
views = require('koa-views'),
favicon = require('koa-favicon'),
cors = require('koa-cors'),
port = process.env.PORT || 3333;
require('dotenv').config({silent: true});
app.use(cors());
app.use(serve('public', {defer: true, maxage: 86400000}));
app.use(logger());
app.use(views('public', {
default: 'jade'
}));
app.use(favicon(__dirname + '/public/favicon.ico'));
// pass env vars to app
app.use(function *(next){
this.state.env = {
node_env: process.env.NODE_ENV,
elasticsearch_url: process.env.ELASTICSEARCH_URL,
proxy_url: process.env.PROXY_URL,
cdn_url: process.env.CDN_URL
};
yield next;
});
app.use(router.routes());
router.get('/', function *(){
yield this.render('index');
});
router.get('/:everything', function *(){
yield this.render('index');
});
app.listen(port, function(){
console.log('Node app is running on port', port);
});