-
Notifications
You must be signed in to change notification settings - Fork 96
/
index.js
50 lines (44 loc) · 1.41 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
require('dotenv').config();
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const express = require('express');
const socketio = require('socket.io');
const http = require('http');
const proxy = require('express-http-proxy');
const session = require('express-session');
const MongoDBStore = require('connect-mongodb-session')(session);
const DataMapper = require('./models/data_mapper');
var sessionStore = new MongoDBStore({
uri: process.env.MONGO_URL,
collection: 'sessions'
});
sessionStore.on('error', function(error) {
console.error(error);
});
var app = express();
var server = http.createServer(app);
var io = socketio(server);
app.use('/scapi', proxy('https://api-v2.soundcloud.com'));
app.set('view engine', 'pug');
app.set('views', __dirname + '/views');
app.use('/static', express.static('static'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json({ limit: '5mb' }));
app.use(cookieParser());
app.set('trust proxy', 1);
app.use(session({
cookie: {
secure: process.env.ENV != 'development'
},
resave: false,
name: 'stretto-next',
saveUninitialized: true,
secret: 'stretto-secret',
store: sessionStore
}));
app.use(require('./controllers'));
require('./controllers/socketio')(io);
server.listen(process.env.PORT || 3000, function() {
console.log("Let's get this party started!");
});
DataMapper.initialize(process.env.MONGO_URL);