This repository has been archived by the owner on Sep 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 225
/
server.js
executable file
·75 lines (65 loc) · 2.17 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
68
69
70
71
72
73
74
75
var handlebars,
express = require('express'),
bodyParser = require('body-parser'),
expHbr = require('express-handlebars'),
session = require('express-session'),
formidable = require('formidable'),
util = require('util'),
app = express(),
path = require('path'),
http = require('http'),
router = express.Router(),
mongoose = require('mongoose'),
mongoStore = require('connect-mongodb'),
nconf = require('nconf').file({ 'file': 'environment.json' }).env(),
connectionString = nconf.get('CUSTOMCONNSTR_MONGOLAB_URI'),
sessionSecretString = nconf.get('SESSION_SECRET_STRING');
// Connect to the database.
mongoose.connect(connectionString);
// If the Node process ends, close the Mongoose connection.
process.on('SIGINT', function() {
mongoose.connection.close(function() {
console.log('Mongoose default connection disconnected through app termination');
process.exit(0);
});
});
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'mongoose connection error:'));
db.once('open', function() {
console.log("we're connected!");
});
// Enforce the `Person` schema.
var Person = mongoose.model('Person', mongoose.Schema({
'name': String,
'email': String,
'zipcode': String,
'face_id': String,
'stock': String,
'homeAddress': String,
'workAddress': String
}));
handlebars = expHbr.create({
'defaultLayout': 'main',
'extname': '.html',
// Uses multiple partials dirs, templates in 'shared/templates/' are shared
// with the client-side of the app (see below).
'partialsDir': [
'views/shared/',
'views/partials/'
]
});
app.engine('html', handlebars.engine);
app.set('view engine', 'html');
app.set('port', process.env.PORT || 3000);
// Saving session in mongoDB.
app.use(session({
'maxAge': null,
'secret': sessionSecretString,
'store': new mongoStore({ 'db': mongoose.connections[0].db })
}));
app.use(bodyParser.raw({limit: '100mb'}));
app.use(express['static'](path.join(__dirname, 'public')));
http.createServer(app).listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});
var routes = require('./routes/serverRoutes.js')(app);