forked from mapcentia/vidi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
75 lines (61 loc) · 2.01 KB
/
index.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
/*
* @author Martin Høgh <mh@mapcentia.com>
* @copyright 2013-2018 MapCentia ApS
* @license http://www.gnu.org/licenses/#AGPL GNU AFFERO GENERAL PUBLIC LICENSE 3
*/
var path = require('path');
require('dotenv').config({path: path.join(__dirname, ".env")});
var express = require('express');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var FileStore = require('session-file-store')(session);
var cors = require('cors');
var config = require('./config/config.js');
var app = express();
app.use(cors());
app.use(cookieParser());
app.use(bodyParser.json({
limit: '50mb'
})
);
// to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true,
limit: '50mb'
}));
app.use(cookieParser());
app.set('trust proxy', 1); // trust first proxy
app.use(session({
store: new FileStore({
ttl: 86400,
logFn: function () {},
path: "/tmp/sessions"
}),
secret: 'keyboard cat',
resave: false,
saveUninitialized: false,
name: "connect.gc2",
cookie: {secure: false}
}));
app.use('/app/:db/:schema?', express.static(path.join(__dirname, 'public'), {maxage: '60s'}));
if (config.staticRoutes) {
for (var key in config.staticRoutes) {
if (config.staticRoutes.hasOwnProperty(key)) {
console.log(key + " -> " + config.staticRoutes[key]);
app.use('/app/:db/:schema/' + key, express.static(path.join(__dirname, config.staticRoutes[key]), {maxage: '60s'}));
}
}
}
app.use('/', express.static(path.join(__dirname, 'public'), {maxage: '1h'}));
app.use(require('./controllers'));
app.use(require('./extensions'));
app.enable('trust proxy');
const port = process.env.PORT ? process.env.PORT : 3000;
var server = app.listen(port, function () {
console.log(`Listening on port ${port}...`);
});
global.io = require('socket.io')(server);
io.on('connection', function (socket) {
console.log(socket.id);
});