Created
July 18, 2022 15:47
-
-
Save FlameWolf/cbe5187b72cde1c85865a2bfe53d731e to your computer and use it in GitHub Desktop.
Configure CORS in Express using middleware
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 app = express(); | |
app.use(async (req, res, next) => { | |
res.setHeader("Access-Control-Allow-Origin", process.env.ALLOW_ORIGIN); | |
res.setHeader("Access-Control-Allow-Credentials", true); | |
res.setHeader("Access-Control-Allow-Headers", "Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Slug, X-UID"); | |
res.setHeader("Access-Control-Allow-Methods", "OPTIONS, POST, PUT, PATCH, GET, DELETE"); | |
next(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment