-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
45 lines (37 loc) · 1.38 KB
/
index.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
var express = require("express");
var cookieParser = require("cookie-parser");
var logger = require("morgan");
var bodyParser = require("body-parser");
const app = express();
const indexRouter = require('./routes/index');
const api = require('./routes/api');
let config;
try {
config = require("./config");
} catch (e) {
console.log("No config file found");
process.exit(0);
}
app.set("view engine", "ejs");
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, HEAD");
res.header("Access-Control-Allow-Headers", "custId, appId, Origin, Content-Type, Cookie, X-CSRF-TOKEN, Accept, Authorization, X-XSRF-TOKEN, Access-Control-Allow-Origin, X-Requested-With");
res.header("Access-Control-Expose-Headers", "Authorization, authenticated");
res.header("Access-Control-Max-Age", "1728000");
res.header("Access-Control-Allow-Credentials", "true");
next();
});
app.use(express.static("public"));
app.use('/', indexRouter);
app.use('/api', api);
app.listen(config.port, () => {
console.log(`Server is running on port : ${config.port}`);
});
module.exports = app;