blob: 33cdb64f575cfa7a9d3d292caf72cbd3f7580d14 [file] [log] [blame]
Timoney, Daniel (dt5972)324ee362017-02-15 10:37:53 -05001var express = require('express');
2var app = express();
3var path = require('path');
4var session = require('express-session');
5var cookieParser = require('cookie-parser');
6var bodyParser = require('body-parser');
7var PropertiesReader = require('properties-reader');
8var properties = PropertiesReader(process.argv[2]); //property file passed
9var morgan = require('morgan');
10var _ = require('lodash');
11//var multer = require('multer');
12//var done=false;
13
14// Check to make sure SDNC_CONFIG_DIR is set
15var sdnc_config_dir = process.env.SDNC_CONFIG_DIR;
16if ( typeof sdnc_config_dir == 'undefined' )
17{
18 console.log('ERROR the SDNC_CONFIG_DIR environmental variable is not set.');
19 return;
20}
21
22
23var moptions = { "stream":
24{
25 write: function(str)
26 {
27 if ( str.indexOf("/javascript") == -1 && str.indexOf("/stylesheets") == -1)
28 {
29 console.log(str);
30 }
31 }
32}
33};
34var accesslog = morgan( "|:method|HTTP/:http-version|:status|:url - requestIP-:remote-addr", moptions);
35
36//var favicon = require('serve-favicon');
37
38// initialize session objects
39app.use(session({
40 secret:'SDN7C',
41 resave: false,
42 saveUninitialized: false
43}));
44
45app.use(cookieParser());
46app.use(bodyParser.urlencoded({
47 extended: true
48}));
49
50app.use(accesslog); // http access log
51app.use(express.static(process.cwd() + '/public')); // static files
52
53
54//app.use('trust proxy', true);
55app.enable('trust proxy');
56
57// view engine setup
58app.set('views', path.join(__dirname, '../views'));
59app.set('view engine', 'ejs');
60
61
62var router = require('./router')(app);
63
64// Error Handling
65app.use(function(err,req,res,next) {
66 res.status(err.status || 500);
67});
68
69module.exports = app;