I have a rails application with cors installed on before_filter:
def cors
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Headers'] = 'X-AUTH-TOKEN, X-API-VERSION, X-Requested-With, Content-Type, Accept, Origin'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
headers['Access-Control-Max-Age'] = "1728000"
end
before_filter :cors
And it works great. Then, if an error is selected on the route, the headers will be overwritten.
def index
object.undefined_method()
end
Answer headers:
Keep-Alive
Content-Length →16399
Content-Type →text/html; charset=utf-8
Date →Thu, 08 May 2014 18:51:20 GMT
Server →WEBrick/1.3.1 (Ruby/2.0.0/2013-11-22)
X-Request-Id →6ace3d4e-4367-452c-a924-c4c490f207de
X-Runtime →0.130761
Although before running before_filter, these headers are missing. Although the 500 error should not exist, I would like front-end developers to be able to give me a more descriptive error than "I did this and CORS did not work." I would expect CORS to be the result.
Thank.
source
share