blob: 898645e86eaf90046b3567a0bf1de7aefa685169 [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');
Rotundo, Al (ar3165)18dcbec2019-07-31 14:46:56 +000011var expressSanitizer = require('express-sanitizer');
Timoney, Daniel (dt5972)324ee362017-02-15 10:37:53 -050012//var multer = require('multer');
13//var done=false;
14
15// Check to make sure SDNC_CONFIG_DIR is set
16var sdnc_config_dir = process.env.SDNC_CONFIG_DIR;
17if ( typeof sdnc_config_dir == 'undefined' )
18{
19 console.log('ERROR the SDNC_CONFIG_DIR environmental variable is not set.');
20 return;
21}
22
23
24var moptions = { "stream":
25{
26 write: function(str)
27 {
28 if ( str.indexOf("/javascript") == -1 && str.indexOf("/stylesheets") == -1)
29 {
30 console.log(str);
31 }
32 }
33}
34};
35var accesslog = morgan( "|:method|HTTP/:http-version|:status|:url - requestIP-:remote-addr", moptions);
36
37//var favicon = require('serve-favicon');
38
39// initialize session objects
40app.use(session({
41 secret:'SDN7C',
42 resave: false,
43 saveUninitialized: false
44}));
45
46app.use(cookieParser());
47app.use(bodyParser.urlencoded({
48 extended: true
49}));
50
Rotundo, Al (ar3165)18dcbec2019-07-31 14:46:56 +000051// mount express-sanitizer here
52app.use(expressSanitizer()); // this line needs to follow bodyParser
53
Timoney, Daniel (dt5972)324ee362017-02-15 10:37:53 -050054app.use(accesslog); // http access log
55app.use(express.static(process.cwd() + '/public')); // static files
56
57
58//app.use('trust proxy', true);
59app.enable('trust proxy');
60
61// view engine setup
62app.set('views', path.join(__dirname, '../views'));
63app.set('view engine', 'ejs');
64
65
66var router = require('./router')(app);
67
68// Error Handling
69app.use(function(err,req,res,next) {
70 res.status(err.status || 500);
71});
72
73module.exports = app;