Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 1 | var express = require('express'); |
| 2 | var app = express(); |
| 3 | var path = require('path'); |
| 4 | var session = require('express-session'); |
| 5 | var cookieParser = require('cookie-parser'); |
| 6 | var bodyParser = require('body-parser'); |
| 7 | var PropertiesReader = require('properties-reader'); |
| 8 | var properties = PropertiesReader(process.argv[2]); //property file passed |
| 9 | var morgan = require('morgan'); |
| 10 | var _ = require('lodash'); |
Rotundo, Al (ar3165) | 18dcbec | 2019-07-31 14:46:56 +0000 | [diff] [blame] | 11 | var expressSanitizer = require('express-sanitizer'); |
Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 12 | //var multer = require('multer'); |
| 13 | //var done=false; |
| 14 | |
| 15 | // Check to make sure SDNC_CONFIG_DIR is set |
| 16 | var sdnc_config_dir = process.env.SDNC_CONFIG_DIR; |
| 17 | if ( typeof sdnc_config_dir == 'undefined' ) |
| 18 | { |
| 19 | console.log('ERROR the SDNC_CONFIG_DIR environmental variable is not set.'); |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | |
| 24 | var 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 | }; |
| 35 | var accesslog = morgan( "|:method|HTTP/:http-version|:status|:url - requestIP-:remote-addr", moptions); |
| 36 | |
| 37 | //var favicon = require('serve-favicon'); |
| 38 | |
| 39 | // initialize session objects |
| 40 | app.use(session({ |
| 41 | secret:'SDN7C', |
| 42 | resave: false, |
| 43 | saveUninitialized: false |
| 44 | })); |
| 45 | |
| 46 | app.use(cookieParser()); |
| 47 | app.use(bodyParser.urlencoded({ |
| 48 | extended: true |
| 49 | })); |
| 50 | |
Rotundo, Al (ar3165) | 18dcbec | 2019-07-31 14:46:56 +0000 | [diff] [blame] | 51 | // mount express-sanitizer here |
| 52 | app.use(expressSanitizer()); // this line needs to follow bodyParser |
| 53 | |
Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 54 | app.use(accesslog); // http access log |
| 55 | app.use(express.static(process.cwd() + '/public')); // static files |
| 56 | |
| 57 | |
| 58 | //app.use('trust proxy', true); |
| 59 | app.enable('trust proxy'); |
| 60 | |
| 61 | // view engine setup |
| 62 | app.set('views', path.join(__dirname, '../views')); |
| 63 | app.set('view engine', 'ejs'); |
| 64 | |
| 65 | |
| 66 | var router = require('./router')(app); |
| 67 | |
| 68 | // Error Handling |
| 69 | app.use(function(err,req,res,next) { |
| 70 | res.status(err.status || 500); |
| 71 | }); |
| 72 | |
| 73 | module.exports = app; |