-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
32 lines (30 loc) · 966 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
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const cors = require("cors");
const routeHandler = require("./index");
const config = require("./config");
app.set("view engine", "pug");
app.use(cors());
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept,x-access-token"
);
res.header("Access-Control-Allow-Credentials", "true");
next();
});
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use("/api", routeHandler);
app.all("*", (req, res) => {
return res.status(404).json({
success: false,
msg: "not found*"
});
});
app.listen(config.port, config.ip, () => {
console.log(`server is running on port ${config.port}`);
});