Skip to content

Commit

Permalink
feat: use cors() instead of hardcode
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Mar 31, 2023
1 parent 659c953 commit 46dfb42
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 17 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"compression": "^1.7.4",
"connect-mongo": "^4.6.0",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dicom-parser": "^1.8.13",
"dicom-to-json": "^1.2.1",
"dotenv": "^16.0.0",
Expand Down
19 changes: 2 additions & 17 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const bodyParser = require("body-parser");
const session = require("express-session");
const cookieParser = require("cookie-parser");
const compress = require("compression");
const cors = require("cors");
const os = require("os");

const mongoose = require("mongoose");
Expand All @@ -19,6 +20,7 @@ require("dotenv");

app.use(compress());
app.use(cookieParser());
app.use(cors());

//#region body parser

Expand Down Expand Up @@ -63,23 +65,6 @@ app.use(passport.session());

//#endregion

//#region global headers

app.use((req, res, next) => {
res.setHeader(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept ,Authorization"
);
res.setHeader("Vary", "Origin");
res.setHeader(
"Access-Control-Allow-Methods",
"POST, GET, OPTIONS, PUT, DELETE"
);
res.setHeader("Access-Control-Allow-Credentials", "true");
next();
});

//#endregion

require("./routes.js")(app);
// require('./services/user/passport')(passport);
Expand Down

0 comments on commit 46dfb42

Please sign in to comment.