-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
85 lines (77 loc) · 2.35 KB
/
server.js
File metadata and controls
85 lines (77 loc) · 2.35 KB
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
/** server.js
@def:
@TODO:
-
*/
"use strict";
// Globally available Object/Modules
global.ARGV = new(require('./lib/argv.js'))(__dirname);
//
global.CONFIG = require('./lib/configLoader.js');
global.Logger = new(require('./lib/logger.js'))();
global.authenticationUtils = require('./lib/authenticationUtils.js');
global.express = require('express');
global.Q = require('kew');
global._ = require("underscore");
global.httpRequest = require("request");
global.fs = require('fs');
global.temp = require('temp');
global.Sequelize = require('sequelize');
//
Logger.msg.initializing();
Logger.dev.info("Configurations loaded: ");
Logger.dev.json(CONFIG);
// Constant Modules
const app = express(),
http = require('http'),
//
cookieParser = require('cookie-parser'),
session = require('express-session'),
MemcachedStore = require('connect-memcached')(session),
bodyParser = require('body-parser'),
// for parsing multipart/form-data
//
portScanner = require('./lib/portscanner.js'),
skipper = require('skipper');
// curatorAPI = require('./curatorAPIRouter.js'),
app.use(skipper());
// Bodyparser for parsing application/json and application/x-www-form-urlencoded
app.use(bodyParser.json());
// for parsing application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({
extended: true
}));
// Create Session and Cookie
app.use(cookieParser());
app.use(session({
secret: 'CatOnKeyboard',
key: 'NodeFrame',
proxy: false,
cookie: {
secure: CONFIG.NodeFrame.Cookie.secure || false,
maxAge: CONFIG.NodeFrame.Cookie.maxAge || 1000 * 60 * 60 * 24,
},
store: new MemcachedStore({
hosts: [`${CONFIG.Memcached.host}:${CONFIG.Memcached.port}`]
}),
resave: true, // auto save of sassion
// don't save cookies with each request, if not logged in.
saveUninitialized: true,
// reset cookie expiry on each request
rolling: true,
}));
// Find available port and Start server
portScanner.findAPortNotInUse(
CONFIG.NodeFrame.ports,
CONFIG.NodeFrame.host, (error, port) => {
if (error)
process.exit(1);
// Start server on available port
app.listen(port, () => {
Logger.log('Server started on ', port, '...');
});
}
);
// set routes
let curatorAPI = require('./curatorAPIRouter.js');
app.use('/api/v1/', curatorAPI);