-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
68 lines (55 loc) · 1.77 KB
/
server.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
55
56
57
58
59
60
61
62
63
64
65
66
67
var express = require('express');
var babelify = require('babelify');
var browserify = require('browserify-middleware');
var nunjucks = require('nunjucks');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var log = require('./server/config/logger');
var index = require('./server/routes/index');
var dbConfig = require('./server/config/db');
var config = require('./client/config');
// initialise express
var app = express();
//We speak JSON
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
//Configure passport
require('./server/config/passport')(app);
//DB connection
mongoose.connect(dbConfig.url, function (err) {
if (err) {
log.error(err);
}
log.info('Connected to DB.');
});
// use nunjucks to process view templates in express
nunjucks.configure('server/templates/views', {
express: app
});
// public assets are served before any dynamic requests
app.use(express.static('public'));
// common packages are precompiled on server start and cached
app.get('/js/' + config.common.bundle, browserify(config.common.packages, {
cache: true,
precompile: true
}));
// any file in /client/scripts will automatically be browserified,
// excluding common packages.
app.use('/js', browserify('./client/scripts', {
external: config.common.packages,
transform: [babelify.configure({
plugins: ['object-assign']
})]
}));
/*
set up any additional server routes (api endpoints, static pages, etc.)
here before the catch-all route for index.html below.
*/
//Users API
require('./server/routes/index')(app);
// start the server
var server = app.listen(process.env.PORT || 3000, function () {
log.info('\nServer ready on port %d\n', server.address().port);
});
//Attach chat component
require('./server/config/chat')(server);