-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
69 lines (52 loc) · 1.33 KB
/
Copy pathapp.js
File metadata and controls
69 lines (52 loc) · 1.33 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const express = require("express");
const cookieParser = require("cookie-parser");
var bodyParser = require("body-parser");
const jwt = require("express-jwt");
const csrf = require("csurf");
const cors = require("cors");
// Initialize Express app
const app = express();
// Using simple a CORS mechanism (preflight)
app.use(
cors({
credentials: true,
origin: "*",
optionsSuccessStatus: 20,
})
);
const csrfProtection = csrf({
cookie: {
httpOnly: true,
},
});
const validation = require("./middlewares/validations");
// Global Variables
global.axios = require("axios");
global.moment = require("moment");
// ******* SET UP MIDDLEWARE ********* //
// Parse Cookie from React App
app.use(cookieParser());
// parse application/x-www-form-urlencoded
app.use(
bodyParser.urlencoded({
extended: true,
})
);
// parse application/json
app.use(bodyParser.json());
// Will handle text/plain requests
app.use(bodyParser.text());
// Setup CORS
// var whitelist = ["http://127.0.0.1:5000", "https://wepredict.herokuapp.com"];
// var corsOptions = {
// origin: whitelist,
// optionsSuccessStatus: 20,
// };
// app.use(require("cors")(corsOptions));
// Setup the API
require("./api")(app, validation, csrfProtection);
app.get("/", (req, res) => {
res.send("<h1>Hello World</h1>");
});
// Export app module
module.exports = app;