Skip to content

Commit a1fdcb3

Browse files
tobias-grasselgebhardt
authored andcommitted
Consider relative URL root configuration
When Rails is deployed to a subdirectory per [the official guide instructions](https://guides.rubyonrails.org/configuring.html#deploy-to-a-subdirectory-relative-url-root), JSON:API should take this into account. Implementation detail: Switched from string concatenation (`+`) to string interpolation because `Rails.application.config.relative_url_root` might be `nil`, which would cause an error as @hlogmans [already stated](#473 (comment)). Tested with: - Setting `RAILS_RELATIVE_URL_ROOT=/subdirectory` - Adding `config.relative_url_root = '/subdirectory'` in application.rb or <environment>.rb Fixes #473
1 parent 1041e34 commit a1fdcb3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/jsonapi/acts_as_resource_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def resource_serializer_klass
152152
end
153153

154154
def base_url
155-
@base_url ||= request.protocol + request.host_with_port
155+
@base_url ||= "#{request.protocol}#{request.host_with_port}#{Rails.application.config.relative_url_root}"
156156
end
157157

158158
def resource_klass_name

0 commit comments

Comments
 (0)