-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (32 loc) · 1.15 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
const express = require("express");
const path = require("path");
const https = require("https");
const fs = require('fs');
const history = require("connect-history-api-fallback");
const jsonServer = require("json-server");
const bodyParser = require("body-parser");
const auth = require("./authMiddleware");
const router = jsonServer.router("serverdata.json");
const enableHttps = false;
const ssloptions = {};
if (enableHttps) {
ssloptions.cert = fs.readFileSync("./ssl/sportsstore.crt");
ssloptions.key = fs.readFileSync("./ssl/sportsstore.pem");
}
const app = express();
app.use(bodyParser.json());
app.use(auth);
app.use("/api", router);
app.use(history());
app.use("/", express.static("./dist/sports-store"));
// app.get("*", (req, res, next) => {
// res.send(path.join(__dirname, "./dist/sports-store/index.html"));
// });
app.listen(80, () => console.log("HTTP Server running on port 80"));
// https.createServer(app).listen(80);
// https.createServer({}, app).listen(443);
if (enableHttps) {
https.createServer(ssloptions, app).listen(443, () => console.log("HTTPS Server running on port 443"));
} else {
console.log("HTTPS disabled");
}