-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathserver.js
47 lines (42 loc) · 1.16 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
// Get dependencies
const express = require("express");
const bodyParser = require("body-parser");
const history = require("connect-history-api-fallback");
const path = require("path");
const app = express();
app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
extended: false
})
);
var distDir = __dirname + "/dist";
app.use(express.static(distDir));
app.use(
history({
disableDotRule: true,
verbose: true
})
);
app.use(express.static(distDir));
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader(
"Access-Control-Allow-Methods",
"GET, POST, OPTIONS, PUT, PATCH, DELETE"
);
res.setHeader(
"Access-Control-Allow-Headers",
"X-Requested-With,content-type"
);
res.setHeader("Access-Control-Allow-Credentials", true);
next();
});
app.get("/", function (req, res) {
res.render(path.join(__dirname + "/dist/index.html"));
});
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
var server = app.listen(process.env.PORT || 8080, function () {
var port = server.address().port;
console.log("App now running on port", port);
});