mirror of
https://github.com/detleph/server.git
synced 2026-09-04 08:36:06 +02:00
Add cors
This commit is contained in:
@@ -14,4 +14,5 @@ Before Runningthis on you local machine some things have to be setup
|
||||
DOMAIN: THE DOMAIN NAME OF THE SERVER
|
||||
MAILPASSWORD: THE PASSWORD FOR THE MAIL ACCOUNT
|
||||
DEV: SWITCH FOR DEV MODE AFFECTS EMAIL SERVER
|
||||
ALLOW_ORIGIN: ORIGIN OF THE PRODUCTION CLIENT (FOR CORS)
|
||||
```
|
||||
|
||||
+3
-1
@@ -20,6 +20,7 @@
|
||||
"homepage": "https://github.com/detleph/server#readme",
|
||||
"dependencies": {
|
||||
"@prisma/client": "^3.3.0",
|
||||
"@types/cors": "^2.8.12",
|
||||
"@types/handlebars": "^4.1.0",
|
||||
"@types/jsonwebtoken": "^8.5.5",
|
||||
"@types/mjml": "^4.7.0",
|
||||
@@ -27,10 +28,11 @@
|
||||
"@types/nodemailer": "^6.4.4",
|
||||
"@types/redis": "^2.8.32",
|
||||
"argon2": "^0.28.2",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^10.0.0",
|
||||
"express": "^4.17.1",
|
||||
"handlebars": "^4.7.7",
|
||||
"express-async-errors": "^3.1.1",
|
||||
"handlebars": "^4.7.7",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"mjml": "^4.11.0",
|
||||
"nanoid": "^3.3.3",
|
||||
|
||||
+15
@@ -3,6 +3,7 @@ import prisma from "./lib/prisma";
|
||||
import eventRouter from "./Routes/event.routes";
|
||||
import adminAuthRouter from "./Routes/admin_auth.routes";
|
||||
import argon2 from "argon2";
|
||||
import cors from "cors";
|
||||
import adminRouter from "./Routes/admin.routes";
|
||||
import organisationRouter from "./Routes/organisation.routes";
|
||||
import groupRouter from "./Routes/group.routes";
|
||||
@@ -36,8 +37,22 @@ async function main() {
|
||||
},
|
||||
update: {},
|
||||
});
|
||||
|
||||
// Allow all CORS requests
|
||||
app.use(cors());
|
||||
} else {
|
||||
logger.info("Using production mode");
|
||||
|
||||
// Configure cors
|
||||
app.use(
|
||||
cors({
|
||||
origin: process.env.ALLOW_ORIGIN,
|
||||
allowedHeaders: ["Content-Type", "Authorization"],
|
||||
preflightContinue: false,
|
||||
methods: ["GET", "PUT", "PATCH", "POST", "DELETE"],
|
||||
optionsSuccessStatus: 204,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// Todo: Everything
|
||||
|
||||
Reference in New Issue
Block a user