Created
November 18, 2021 01:06
-
-
Save diegofcornejo/40494ac0e36bf6c9bfb02e68cdfedba8 to your computer and use it in GitHub Desktop.
Vercel basic redirect service
This file contains hidden or 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 cors = fn => async (req, res) => { | |
| res.setHeader('Access-Control-Allow-Credentials', true) | |
| res.setHeader('Access-Control-Allow-Origin', '*') | |
| // another common pattern | |
| // res.setHeader('Access-Control-Allow-Origin', req.headers.origin); | |
| // res.setHeader('Access-Control-Allow-Methods', 'GET,OPTIONS,PATCH,DELETE,POST,PUT') | |
| res.setHeader('Access-Control-Allow-Methods', 'GET,OPTIONS') | |
| 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) | |
| } | |
| const handler = (req, res) => { | |
| return res.redirect('https://blog.diegocornejo.com'); | |
| }; | |
| module.exports = cors(handler); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment