-
-
Save uknownothingsnow/7020717 to your computer and use it in GitHub Desktop.
allowCrossDomain middleware for expressjs or compundjs
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
#CORS middleware | |
allowCrossDomain = (req, res, next) -> | |
res.header 'Access-Control-Allow-Origin', '*' | |
res.header 'Access-Control-Allow-Methods', 'OPTIONS,GET,PUT,POST,DELETE' | |
res.header 'Access-Control-Allow-Headers', 'Content-Type, X-Requested-With' | |
next() | |
# Cut off OPTIONS requests and just send true as response | |
handleOptionsMethod = (req, res, next) -> | |
return res.send(200) if req.method == 'OPTIONS' | |
next() | |
module.exports = (compound) -> | |
express = require 'express' | |
app = compound.app | |
app.configure -> | |
# removed config above for conciseness ... | |
app.use allowCrossDomain | |
app.use handleOptionsMethod | |
# removed config below for conciseness ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
allowcrossdomain middleware for express and compoundjs