-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (43 loc) · 1.26 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
global._ = require('lodash');
global.t = require('moment');
var firebaseRef = require('./firebase-ref');
var bodyParser = require('body-parser');
function run(appdir) {
var express = require('express');
var app = express();
app.dir = process.cwd();
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
// things to do on each request
app.use(function (req, res, next) {
// tell the client what firebase to use
if(process.env.NODE_ENV === 'production') {
res.cookie('rootRef', firebaseRef.prod);
}
else {
// development mode
res.cookie('rootRef', firebaseRef.dev);
// log the request
console.log(t().format('HH:MM'), req.method , '\n' + req.url, req.socket.bytesRead);
}
next();
});
// static files
app.use(express.static(app.dir + '/public'));
//handle all routes with frontend angular ui route
app.get('/*',function(req,res){
res.sendFile('index.html',{root:'./public/'});
});
// Standard error handling
app.use(function(err, req, res, next){
console.error(err.stack);
res.status(500).send('Something broke!');
});
// Fire up server
var server = app.listen(process.env.PORT || 5555, function() {
console.log('Listening on port %d', server.address().port);
});
}
run(process.cwd());