-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
53 lines (45 loc) · 1.41 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
46
47
48
49
50
51
52
53
const express = require("express");
const app = express();
const helmet = require("helmet");
const morganMiddleware = require("./middlewares/morganMiddleware");
const cookieParser = require("cookie-parser");
const cors = require("cors");
const csrf = require("csurf");
const { sequelize } = require("./models");
// const db = require("./models/index.js");
const logger = require("./config/logger");
const Router = require("./routes");
app.use(
cors({
origin: ["https://rendev99.com", "http://localhost:3000"], //["http://localhost:3001"],
credentials: true,
methods: "GET, HEAD, PUT, PATCH, POST, DELETE",
})
);
sequelize
.sync({ force: false })
.then(() => {
console.log("SEQUELIZE -=CONNECTED=-");
})
.catch((error) => {
console.log(error);
});
const cspOption = {
directives : {
...helmet.contentSecurityPolicy.getDefaultDirectives(),
"script-src" : ["'self'", "*.rendev99.com"],
"img-src": ["'self'", "s3.amazonaws.com"]
}
}
app.use(cookieParser());
app.use(morganMiddleware);
app.use(helmet({ contentSecurityPolicy: cspOption, crossOriginEmbedderPolicy: false, crossOriginResourcePolicy: false }));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use("/api", Router);
app.use(csrf({ cookie: { httpOnly: true, sameSite:"None", secure:true }}))
app.use((req, res, next) => {
res.cookie('XSRF-TOKEN', req.csrfToken())
next()
})
module.exports = app;