Created
April 26, 2015 10:32
-
-
Save bobbysciacchitano/8af6872e14dd37ab802f to your computer and use it in GitHub Desktop.
Express CORS 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
var middleware = function(request, response, next) { | |
response.header("Access-Control-Allow-Origin", "*"); | |
response.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization"); | |
response.header("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE"); | |
response.header("Access-Control-Max-Age", "432000"); | |
if(request.method === 'OPTIONS') { | |
response.status(200).send(); | |
return; | |
} | |
next(); | |
}; | |
module.exports = middleware; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can adjust this to your taste for instance if you only want to expose methods for a specific resource, etc.