-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathserver.js
65 lines (47 loc) · 2.26 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
// server.js
// set up ======================================================================
// get all the tools we need
var express = require('express');
var expressLayouts = require('express-ejs-layouts')
var favicon = require('serve-favicon');
var app = express();
var port = process.env.PORT || 8001;
var mongoose = require('mongoose');
var passport = require('passport');
var flash = require('connect-flash');
var morgan = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var colors = require('colors');
var constants = require('./scripts/constants');
var config = require(constants.paths.config + '/config');
// configuration ===============================================================
require('./scripts/database'); // load database management scripts
require('./config/passport')(passport); // pass passport for configuration
// set up our express application
app.use(morgan('dev')); // log every request to the console
app.use(cookieParser()); // read cookies (needed for auth)
app.use(bodyParser.json()); // get information from html forms
app.use(bodyParser.urlencoded({ extended: true }));
app.use(favicon(__dirname + '/public/favicon.ico'));
app.set('view engine', 'ejs'); // set up ejs for templating
app.set('layout', 'layouts/main')
// set development environment configuration
if (app.get('env') === 'development') {
app.locals.pretty = true; //render html output with proper formating
}
app.use(expressLayouts);
// required for passport
require('./scripts/session')(app);
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash()); // use connect-flash for flash messages stored in session
// routes ======================================================================
require('./routes/main')(app, passport);
// launch ======================================================================
app.listen(port);
var util = require('./scripts/util');
var appInfoServ = require('./services/appService');
var appInfo = appInfoServ.info();
console.log(colors.blue(util.formatString("\nApplication: %s ver %s:%s", appInfo.name, appInfo.version, appInfo.gitHash )));
console.log(colors.blue(util.formatString(' running at port %s', port)));