-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
38 lines (31 loc) · 1.04 KB
/
server.js
File metadata and controls
38 lines (31 loc) · 1.04 KB
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
const fs = require("fs"),
privateKey = fs.readFileSync("sslcert/key.pem", "utf8"), // SSL cert
certificate = fs.readFileSync("sslcert/cert.pem", "utf8"),
credentials = { key: privateKey, cert: certificate }, // add to createServer and change http to https
https = require("https"),
http = require("http"),
express = require("express"),
app = express(),
httpsServer = https.createServer(credentials, app),
httpServer = http.createServer(app),
port = process.env.PORT || 9000,
{ ExpressPeerServer } = require("peer"),
cors = require("cors");
global.server = httpServer;
const sockets = require('./sockets');
const corsOptions = {
origin: "https://ib-r.github.io",
optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
};
const peerServer = ExpressPeerServer(server, {
debug: true,
path: "/",
cors: false,
});
app.use(cors(corsOptions));
app.use("/", peerServer);
app.get("/s", (req, res, next) => {
res.json({ hello: 123 });
});
server.listen(port);
console.log(`Server is running on port ${port} with SSL`);