8000 Added extra check for OPTIONS to prevent CORS issues. · maciejkuran/forms-validation-API@9e5bbdb · GitHub
[go: up one dir, main page]

Skip to content

Commit 9e5bbdb

Browse files
committed
Added extra check for OPTIONS to prevent CORS issues.
1 parent 9b5db5b commit 9e5bbdb

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

pages/api/email.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ const handler = (req: NextApiRequest, res: NextApiResponse) => {
1212

1313
if (!rateLimitOk) return;
1414

15+
//Preventing CORS issues.If you try to send a POST etc.. request , the preflight will send it’s ‘first army’ to check the ‘battle field’. But this army is not the request itself, but an OPTION request. That’s why in our API we need to handle OPTION request.
16+
if (req.method === 'OPTIONS') {
17+
return res.status(200).json({
18+
body: 'OK',
19+
});
20+
}
21+
1522
if (req.method !== 'POST') {
1623
return res.status(400).json({ error: 'Invalid request method. Accepted: POST' });
1724
}

pages/api/password.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ const handler = (req: NextApiRequest, res: NextApiResponse) => {
1212

1313
if (!rateLimitOk) return;
1414

15+
//Preventing CORS issues.If you try to send a POST etc.. request , the preflight will send it’s ‘first army’ to check the ‘battle field’. But this army is not the request itself, but an OPTION request. That’s why in our API we need to handle OPTION request.
16+
if (req.method === 'OPTIONS') {
17+
return res.status(200).json({
18+
body: 'OK',
19+
});
20+
}
21+
1522
if (req.method !== 'POST') {
1623
return res.status(400).json({ error: 'Invalid request method. Accepted: POST' });
1724
}

pages/api/sign-in.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ const handler = (req: NextApiRequest, res: NextApiResponse) => {
1313

1414
if (!rateLimitOk) return;
1515

16+
//Preventing CORS issues.If you try to send a POST etc.. request , the preflight will send it’s ‘first army’ to check the ‘battle field’. But this army is not the request itself, but an OPTION request. That’s why in our API we need to handle OPTION request.
17+
if (req.method === 'OPTIONS') {
18+
return res.status(200).json({
19+
body: 'OK',
20+
});
21+
}
22+
1623
if (req.method !== 'POST') {
1724
return res.status(400).json({ error: 'Invalid request method. Accepted: POST' });
1825
}

pages/api/sign-up.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ const handler = (req: NextApiRequest, res: NextApiResponse) => {
1313

1414
if (!rateLimitOk) return;
1515

16+
//Preventing CORS issues.If you try to send a POST etc.. request , the preflight will send it’s ‘first army’ to check the ‘battle field’. But this army is not the request itself, but an OPTION request. That’s why in our API we need to handle OPTION request.
17+
if (req.method === 'OPTIONS') {
18+
return res.status(200).json({
19+
body: 'OK',
20+
});
21+
}
22+
1623
if (req.method !== 'POST') {
1724
return res.status(400).json({ error: 'Invalid request method. Accepted: POST' });
1825
}

0 commit comments

Comments
 (0)
0