Skip to content

Commit

Permalink
configure cors in nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jul 19, 2021
1 parent f74f871 commit c3b9e29
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
30 changes: 15 additions & 15 deletions config/initializers/cors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

# Read more: https://github.com/cyu/rack-cors

Rails.application.config.middleware.insert_before 0,
Rack::Cors,
debug: true,
logger:
(-> { Rails.logger }) do
allow do
origins Rails.application.config.allowed_cors_origins.deep_dup
# origins "*"
resource "*",
headers: :any,
expose: %w[X-Credential-Username X-Anonymous-Consumer],
methods: %i[get post put patch delete options head],
credentials: true
end
end
# Rails.application.config.middleware.insert_before 0,
# Rack::Cors,
# debug: true,
# logger:
# (-> { Rails.logger }) do
# allow do
# origins Rails.application.config.allowed_cors_origins.deep_dup
# # origins "*"
# resource "*",
# headers: :any,
# expose: %w[X-Credential-Username X-Anonymous-Consumer],
# methods: %i[get post put patch delete options head],
# credentials: true
# end
# end
23 changes: 23 additions & 0 deletions vendor/docker/webapp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@ server {
return 301 https://support.datacite.org/docs/api;
}

location / {
# enable CORS
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Methods' 'GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,Content-Type,Accept,Accept-Encoding,Origin,User-Agent,Cache-Control,Keep-Alive,Authorization';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range,X-Credential-Username,X-Anonymous-Consumer,Authorization';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}

if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Methods' 'GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,Content-Type,Accept,Accept-Encoding,Origin,User-Agent,Cache-Control,Keep-Alive,Authorization';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range,X-Credential-Username,X-Anonymous-Consumer,Authorization';
}
}

location /client-api/graphql {
gzip on;
gzip_min_length 1000;
Expand Down

0 comments on commit c3b9e29

Please sign in to comment.