-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
35 lines (28 loc) · 955 Bytes
/
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
const express = require("express");
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/sport-store"));
app.listen(80,
() => console.log("HTTP Server running on port 80"));
if (enableHttps) {
https.createServer(ssloptions, app).listen(443,
() => console.log("HTTPS Server running on port 443"));
} else {
console.log("HTTPS disabled");
}