-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
49 lines (40 loc) · 1.26 KB
/
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
46
47
48
const express = require('express');
const passport = require('passport');
const config = require('./config/config');
const glob = require('glob');
const mongoose = require('mongoose');
mongoose.promise = global.Promise;
mongoose.connect(config.db,{
keepAlive: true,
reconnectTries: Number.MAX_VALUE,
useMongoClient: true
});
const db = mongoose.connection;
db.on('error', () => {
throw new Error('unable to connect to database at ' + config.db);
});
const models = glob.sync(config.root + '/app/models/*.js');
models.forEach(function (model) {
require(model);
});
const app = express();
const seedDB = require('./app/seed/seed')
//seedDB()
//const camps = seed.createCampSites(15);
module.exports = require('./config/express')(app, config, passport );
//hot reload in development
if(app.locals.ENV_DEVELOPMENT) {
const chokidar = require('chokidar');
const watcher = chokidar.watch('./app');
watcher.on('ready', function() {
watcher.on('all', function() {
console.log("Clearing /dist/ module cache from server")
Object.keys(require.cache).forEach(function(id) {
if (/[\/\\]app[\/\\]/.test(id)) delete require.cache[id]
})
})
})
}
app.listen(config.port, () => {
console.log('Express server listening on port ' + config.port);
});