Skip to content

Instantly share code, notes, and snippets.

@ghostbar
Last active December 19, 2015 02:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghostbar/78afb29bba823453cdf7 to your computer and use it in GitHub Desktop.
Save ghostbar/78afb29bba823453cdf7 to your computer and use it in GitHub Desktop.
This is a very simple implementation on how to handle the pre-flight options on Restify without filter of Origin.
# Handling the OPTIONS method requests by browsers.
unkMH = (req, res) ->
if req.method.toLowerCase() is 'options'
allowHeaders = ['Accept', 'Accept-Version', 'Content-Type', 'Api-Version', 'Authorization']
if res.methods.indexOf('OPTIONS') is -1
res.methods.push('OPTIONS')
res.header 'Access-Control-Allow-Credentials', true
res.header 'Access-Control-Allow-Headers', allowHeaders.join ', '
res.header 'Access-Control-Allow-Methods', res.methods.join ', '
res.header 'Access-Control-Allow-Origin', req.headers.origin
return res.send 204
else
return res.send new restify.MethodNotAllowedError()
app.on 'MethodNotAllowed', unkMH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment