-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
107 lines (86 loc) · 3.07 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Modules
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var Session = require('express-session')
var RedisStore = require('connect-redis')(Session);
var busboy = require('connect-busboy');
var morgan = require('morgan');
var path = require('path');
var debug = require('debug');
var https = require('https');
var http = require('http');
var fs = require('fs');
var cas_validate = require('cas_validate');
//SET ENV VARIABLES
var env = (process.env.ENV ? process.env.ENV : 'development').toLowerCase(),
secret = "ABCDE";
app.set('port', parseInt(process.env.PORT) || 8080);
app.set('env', env || 'development');
app.set('s3 datasets bucket', process.env.S3_DATASETS_BUCKET || 'datasets-test');
app.set('s3 jobs bucket', process.env.S3_JOBS_BUCKET || 'jobs-test');
// Use Jade to render templates
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
// Serve a couple of static dirs
app.use(express.static(__dirname + '/public'));
app.use('/bower_components', express.static(__dirname + '/bower_components'));
app.use(function (req, res, next){
if(req.secure){
return next();
};
res.redirect('https://'+req.host+req.url);
});
var cas_config = {
'cas_host' : 'my107.iit.edu',
'service' : 'https://64.131.111.55'
};
app.use(cookieParser(secret));
var session = Session({
store: new RedisStore({}),
secret: secret,
resave: false,
saveUninitialized: true
});
app.use(session);
app.use(function(req, res, next) {
console.log(req.session);
next();
});
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use('/signout', cas_validate.logout(cas_config));
app.use(cas_validate.ssoff());
app.use(cas_validate.ticket(cas_config));
app.use(cas_validate.check_or_redirect(cas_config));
app.use(busboy());
app.use(express.static(path.join(__dirname, 'public')));
app.set('views', path.join(__dirname, 'views'));
var index = require('./routes/index.js');
var datasets = require('./routes/datasets.js');
var jobs = require('./routes/jobs.js');
var processes = require('./routes/processes.js');
app.use('/datasets', datasets);
app.use('/jobs', jobs);
app.use('/processes', processes);
app.use('/', index);
// start app ===============================================
var connections = require('./connections');
var pubSub = require('./api/pubSub.js');
var socketEmitter = require('./api/socketEmitter.js');
var httpsOptions = {
key : fs.readFileSync('./keys/hadoopAutomation-key.pem'),
cert : fs.readFileSync('./keys/hadoopAutomation-cert.pem')
}
connections.on('connected', function(){
http.createServer(app).listen(80);
var server = https.createServer(httpsOptions, app).listen(app.get('port'), function() {
console.log("Using " + app.get('env').toUpperCase() + " connection settings");
console.log("Listening on port " + app.get('port'));
socketEmitter.createServer(server, session);
pubSub.start();
});
});
module.exports = app;