Skip to content

Instantly share code, notes, and snippets.

@seansullivan
Last active December 10, 2015 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save seansullivan/4507044 to your computer and use it in GitHub Desktop.
Save seansullivan/4507044 to your computer and use it in GitHub Desktop.
Cross Domain Headers for CompoundJS
#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