Add handling of OPTIONS request to /api namespace

* It allows access from anywhere via wildcard origin
* It sets the timeout to an hour
* It allows all standard HTTP verbs + OPTIONS
This commit is contained in:
Maciej Szlosarczyk 2018-10-16 09:32:49 +03:00
parent c148c7e0c0
commit 58c928226d
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
4 changed files with 51 additions and 0 deletions

View file

@ -0,0 +1,20 @@
module Api
class CorsController < ApplicationController
skip_before_action :verify_authenticity_token
skip_authorization_check
def cors_preflight_check
set_access_control_headers
render json: { status: :ok }
end
def set_access_control_headers
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, PATCH, DELETE, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Origin, Content-Type, Accept, ' \
'Authorization, Token, Auth-Token, '\
'Email, X-User-Token, X-User-Email'
response.headers['Access-Control-Max-Age'] = '3600'
end
end
end