Skip to content

Commit

Permalink
updated header options
Browse files Browse the repository at this point in the history
  • Loading branch information
jazicorn committed Oct 5, 2023
1 parent 23d622e commit 6125885
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ export default class VarDeclare {
switch(req.method) {
case('GET'):
try {
res.options("*", (req, res) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "GET, HEAD, PUT, PATCH, POST, DELETE, OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
res.sendStatus(204);
});

const result = await randomQuestion;

res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
res.setHeader('Access-Control-Allow-Methods', 'GET, PUT, PATCH, POST, DELETE');
Expand All @@ -55,6 +63,13 @@ export default class VarDeclare {
switch(req.method) {
case('GET'):
try {
res.options("*", (req, res) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "GET, HEAD, PUT, PATCH, POST, DELETE, OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
res.sendStatus(204);
});

const result = await question;
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
Expand All @@ -75,6 +90,12 @@ export default class VarDeclare {
switch(req.method) {
case('GET'):
try {
res.options("*", (req, res) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "GET, HEAD, PUT, PATCH, POST, DELETE, OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
res.sendStatus(204);
});
const result = await question;
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
Expand Down
5 changes: 3 additions & 2 deletions apps/api/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ class App {
origin: [
"https://vercel.com/jazicorn/recodecamp-web",
"https://recodecamp-web.vercel.app",
"https://recodecamp-web.vercel.app/",
"https://recodecamp-web.vercel.app/#/",
"https://www.recodecamp.com"
],
"methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
"methods": "GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS",
"preflightContinue": false,
"optionsSuccessStatus": 204
}));
Expand Down Expand Up @@ -80,7 +81,7 @@ class App {
this.app.use('/', (req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
res.setHeader('Access-Control-Allow-Methods', 'GET, PUT, PATCH, POST, DELETE');
res.setHeader('Access-Control-Allow-Methods', 'GET, PUT, PATCH, POST, DELETE, OPTIONS');
next();
},
controller.router
Expand Down

0 comments on commit 6125885

Please sign in to comment.