-
Notifications
You must be signed in to change notification settings - Fork 0
/
deepstream.js
40 lines (32 loc) · 1.04 KB
/
deepstream.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
'use strict';
const express = require('express');
const fallback = require('express-history-api-fallback');
const DeepstreamServer = require('deepstream.io');
const C = DeepstreamServer.constants;
var fs = require('fs');
var key = fs.readFileSync('private.key');
var cert = fs.readFileSync('mydomain.crt');
const app = express();
const port = process.env.PORT || 8081;
const root = `${__dirname}/public`;
var options = {
key: key,
cert: cert
};
// serve statically through express
// TODO: serve through nginx later for better performance or use CDN
app.use(express.static(root));
// start the main express server
// app.listen(port);
// route everthing else back to the index.html for the SPA to work nicely
// NOTE: it's important to load this after the /api route to not overwrite it
app.use(fallback('index.html', {root}));
var https = require('https');
https.createServer(options, app).listen(8081);
// setup deepstream server
const server = new DeepstreamServer({
host: '0.0.0.0',
port: 6020,
});
// start the server
server.start();