Last active
December 10, 2015 23:08
-
-
Save seansullivan/4507044 to your computer and use it in GitHub Desktop.
Cross Domain Headers for CompoundJS
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', '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