-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (35 loc) · 987 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
36
37
38
39
40
41
const express = require("express");
const serveStatic = require("serve-static");
const path = require("path");
const cors = require("cors");
const app = express();
app.use(
express.urlencoded({
extended: true,
})
);
app.use(cors({ origin: true })); // enable origin cors
app.use(serveStatic(path.join(__dirname, "dist")));
app.get(/.*/, function (req, res) {
res.sendFile(__dirname + "/dist/index.html");
});
app.options("*", cors());
app.use(
cors({
origin: ["*"],
credentials: true,
})
);
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET,PUT,PATCH,POST,DELETE");
res.header("Access-Control-Allow-Headers", "Content-Type");
app.use(cors());
next();
});
// const port = process.env.PORT || 8080;
// app.listen(port);
const server = app.listen(process.env.PORT || 8080, () => {
const port = server.address().port;
console.log(`Express is working on port ${port}`);
});