-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
28 lines (25 loc) · 1.02 KB
/
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
const WebSocket = require('ws')
const TransparentJSONSocket = require('./lib/server/socket');
const Sync9Server = require('./lib/server/sync9_server');
const https = require('https');
const express = require('express');
const port = 1200;
const path = '/interoperability';
const fs = require('fs');
var backend = new Sync9Server(startServer);
function startServer() {
// Create a web server to serve files and listen to WebSocket connections
var app = express();
app.use(path, express.static('static'));
var server = https.createServer({
key: fs.readFileSync('/etc/letsencrypt/live/invisible.college/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/invisible.college/cert.pem'),
}, app);
// Connect any incoming WebSocket connection to the server
var wss = new WebSocket.Server({server: server});
wss.on('connection', function(ws) {
var stream = new TransparentJSONSocket(ws);
backend.listen(stream);
});
server.listen(port, () => console.log(`Listening on http://localhost:${port}${path}:`));
}