-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
50 lines (42 loc) · 1.31 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const fs = require("fs");
const path = require("path");
const { resolve, relative } = require("path");
const express = require("express");
const Gun = require("gun");
require("gun/lib/radix");
require("gun/lib/radisk");
require("gun/lib/store");
require("gun/lib/rindexed");
require("gun/nts");
require("gun/lib/webrtc");
var https = require("https");
var http = require("http");
console.log("starting ouronote server");
const PORT = process.env.PORT || 80;
const HTTPS_PORT = process.env.HTTPS_PORT || 443;
console.log({ PORT, HTTPS_PORT });
let httpsServer;
const app = express();
app.use(Gun.serve);
app.use(express.static(__dirname + "/dist/demo"));
app.get("/*", function (req, res) {
res.sendFile(path.join(__dirname, "dist/demo", "index.html"));
});
try {
const pkf = resolve(__dirname, "ouronote-dev.key");
const privateKey = fs.readFileSync(pkf);
const cf = resolve(__dirname, "ouronote-dev.crt");
const certificate = fs.readFileSync(cf);
const EXPRESS_OPTS = {
key: privateKey,
cert: certificate,
};
httpsServer = https.createServer(EXPRESS_OPTS, app).listen(HTTPS_PORT);
} catch (e) {
console.error("Error starting HTTPS server: ", e);
console.log("will default to HTTP");
}
// app.listen = function(){
// }
const server = app.listen(PORT);
const gun = Gun({ web: httpsServer || server });