-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
34 lines (29 loc) · 950 Bytes
/
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
const bodyParser = require('body-parser');
const express = require('express');
const morgan = require('morgan');
const session = require('express-session');
// internal app deps
const datastore = require('./datastore');
const authProvider = require('./auth-provider');
const app = express();
app.use(morgan('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.set('trust proxy', 1); // trust first proxy
app.use(session({
genid: function (req) {
return authProvider.genRandomString()
},
secret: 'xyzsecret',
resave: false,
saveUninitialized: true,
cookie: {secure: false}
}));
const deviceConnections = {};
const appPort = process.env.PORT || "3000";
const server = app.listen(appPort, function () {
const host = server.address().address;
const port = server.address().port;
console.log('Smart Home Cloud and App listening at %s:%s', host, port);
authProvider.registerAuth(app);
});