From f583e9e7e4347cd5afc03ef2f2fb8151af66f43d Mon Sep 17 00:00:00 2001 From: jazicorn <40859840+jazicorn@users.noreply.github.com> Date: Thu, 5 Oct 2023 14:08:33 -0400 Subject: [PATCH] updated header options --- apps/api/src/server.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/apps/api/src/server.ts b/apps/api/src/server.ts index 5d7ee51..652b7f6 100644 --- a/apps/api/src/server.ts +++ b/apps/api/src/server.ts @@ -23,12 +23,7 @@ class App { constructor(authControllers, controllers) { // #TODO | figure out how to turn env var string to an array of strings - this.corsOptions = [ - "https://vercel.com/jazicorn/recodecamp-web", - "https://recodecamp-web.vercel.app", - "https://www.recodecamp.com" - ]; - console.log(this.corsOptions) + this.corsOptions = ''; this.app = express(); this.port = parseInt(process.env.PORT as string) || 8000; this.initMiddlewares(); @@ -44,12 +39,20 @@ class App { this.app.use(cookieParser()); this.app.options("*", (req, res) => { res.setHeader("Access-Control-Allow-Origin", "*"); - res.setHeader("Access-Control-Allow-Methods", "PUT, PATCH, POST, GET, DELETE, OPTIONS"); + res.setHeader("Access-Control-Allow-Methods", "GET, HEAD, PUT, PATCH, POST, DELETE, OPTIONS"); res.setHeader("Access-Control-Allow-Headers", "Content-Type"); res.sendStatus(204); }); this.app.use(cors({ - origin: this.corsOptions + origin: [ + "https://vercel.com/jazicorn/recodecamp-web", + "https://recodecamp-web.vercel.app", + "https://recodecamp-web.vercel.app/#/", + "https://www.recodecamp.com" + ], + "methods": "GET,HEAD,PUT,PATCH,POST,DELETE", + "preflightContinue": false, + "optionsSuccessStatus": 204 })); // this.app.use( "/", (req, res, next) => { // res.setHeader('access-control-allow-origin', '*');