summaryrefslogtreecommitdiffstats
path: root/admportal/server/app.js
blob: 33cdb64f575cfa7a9d3d292caf72cbd3f7580d14 (plain)
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
var express = require('express');
var app = express();
var path = require('path');
var session = require('express-session');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var PropertiesReader = require('properties-reader');
var properties = PropertiesReader(process.argv[2]); //property file passed
var morgan = require('morgan');
var _ = require('lodash');
//var multer = require('multer');
//var done=false;

// Check to make sure SDNC_CONFIG_DIR is set
var sdnc_config_dir = process.env.SDNC_CONFIG_DIR;
if ( typeof sdnc_config_dir == 'undefined' )
{
	console.log('ERROR the SDNC_CONFIG_DIR environmental variable is not set.');
	return;
}
	

var moptions = { "stream": 
{
	write: function(str)
	{
		if ( str.indexOf("/javascript") == -1 && str.indexOf("/stylesheets") == -1)
		{
			console.log(str); 
		}
	}
}
};
var accesslog = morgan( "|:method|HTTP/:http-version|:status|:url - requestIP-:remote-addr", moptions);

//var favicon = require('serve-favicon');

// initialize session objects
app.use(session({
	secret:'SDN7C',
	resave: false,
	saveUninitialized: false
}));

app.use(cookieParser());
app.use(bodyParser.urlencoded({
  extended: true
}));

app.use(accesslog); // http access log
app.use(express.static(process.cwd() + '/public')); // static files


//app.use('trust proxy', true);
app.enable('trust proxy');

// view engine setup
app.set('views', path.join(__dirname, '../views'));
app.set('view engine', 'ejs');


var router = require('./router')(app);

// Error Handling
app.use(function(err,req,res,next) {
	res.status(err.status || 500);
});

module.exports = app;