Created
July 2, 2021 11:38
-
-
Save microchipgnu/933c9ca3f71bbadc0e5e33d5ab0e4340 to your computer and use it in GitHub Desktop.
Allow Cors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const allowCors = (fn) => async (req, res) => { | |
res.setHeader("Access-Control-Allow-Credentials", true) | |
res.setHeader("Access-Control-Allow-Origin", "*") | |
res.setHeader( | |
"Access-Control-Allow-Methods", | |
"GET,OPTIONS,PATCH,DELETE,POST,PUT" | |
) | |
res.setHeader( | |
"Access-Control-Allow-Headers", | |
"X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" | |
) | |
if (req.method === "OPTIONS") { | |
res.status(200).end() | |
return | |
} | |
return await fn(req, res) | |
} | |
export default allowCors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment