-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (43 loc) · 1.49 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
50
51
52
53
54
global._ = require('lodash');
global.t = require('moment');
var cookieParser = require('cookie-parser'),
Firebase = require("firebase"),
env = process.env.NODE_ENV || 'development',
// config = require('./config/config')[env],
routes = require('./server/routes'),
// routes = require('./server/routes.js');
path = require('path'),
express = require('express'),
bodyParser = require('body-parser'),
app = express();
var rootRefUrl = 'my firebase rootRef';
app.use(cookieParser());
// things to do on each request
app.use(function (req, res, next) {
// log each request in development environment
if(env !== 'production') console.log(t().format('HH:MM'), req.method, req.url, req.socket.bytesRead);
// tell the client what firebase to use
res.cookie('rootRef', rootRefUrl);
next();
});
// static files
console.log('---------',__dirname);
app.use(express.static(path.join(__dirname, 'public')));
// Standard error handling
app.use(function(err, req, res, next){
console.error(err.stack);
res.status(500).send('Something broke!');
});
// to support JSON-encoded bodies
app.use(bodyParser.json());
// to support URL-encoded bodies
app.use(bodyParser.urlencoded({
extended: true
}));
var data = 'Iyanu-Tomiwa';
routes(app, data);
// app.get('/', routes.partials);
var server = app.listen(process.env.PORT || 5000, function() {
console.log('Listening on port %d', server.address().port);
});
module.exports = app;