-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (46 loc) · 1.45 KB
/
index.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
51
52
require("dotenv");
const https = require("https");
const fs = require("fs");
const express = require("express");
const bodyParser = require("body-parser");
const roots = require("./routes/roots");
const cors = require("cors");
const path = require("path");
var port = 3001;
var app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(async (req, res, next) => {
console.log(`\nEndpoint Hit: ${req.method} ${req.originalUrl}\n`);
next();
});
app.use("/api", roots);
app.use(express.static(path.join(__dirname, '/docs')));
app.route("/").get((req, res) => {
res.sendFile(path.join(__dirname + "/docs/index.html"));
});
if (process.env.NODE_ENV == "production") {
// This sets the options for https so that it finds the ssl certificates
var privateKey = fs.readFileSync(
"/etc/letsencrypt/live/offlinequran.com-0002/privkey.pem"
);
var certificate = fs.readFileSync(
"/etc/letsencrypt/live/offlinequran.com-0002/cert.pem"
)
var chain = fs.readFileSync(
"/etc/letsencrypt/live/offlinequran.com-0002/fullchain.pem"
);
const httpsOptions = {
cert: certificate,
key: privateKey,
ca: chain,
};
var httpsServer = https.createServer(httpsOptions, app).listen(port, () => {
console.log("Serving on https");
});
} else if (process.env.NODE_ENV == "development") {
app.listen(port, () => {
console.log("Listening on port " + port);
});
}