Skip to content

Bad links with engine mounted as root #1303

@brcebn

Description

@brcebn

This issue is a (choose one):

  • Problem/bug report.
  • Feature request.
  • Request for support. Note: Please try to avoid submitting issues for support requests. Use Gitter instead.

Checklist before submitting:

  • I've searched for an existing issue.
  • I've asked my question on Gitter and have not received a satisfactory answer.
  • I've included a complete bug report template. This step helps us and allows us to see the bug without trying to reproduce the problem from your description. It helps you because you will frequently detect if it's a problem specific to your project.
  • The feature I'm asking for is compliant with the JSON:API spec.

Description

As described on lib/jsonapi/link_builder.rb#L139,

def resource_url(source)
    "#{ base_url }#{ engine_mount_point }#{ resource_path(source) }"
end

But in this case:

constraints subdomain: 'api' do
    mount MyEngine::Engine, at: '/' if defined?(MyEngine::Engine)
  end

This creates a double / due to root value of engine_mount_point.

I guess a little update of:

@engine_mount_point = @engine ? @engine.routes.find_script_name({}) : ""

should be enough.

Current result:

{
    "data": {
        "id": "ed526d56-cc7e-41f4-8e99-fccf73fb7500",
        "type": "users",
        "links": {
            "self": "//v1/users/ed526d56-cc7e-41f4-8e99-fccf73fb7500"
        },
        "attributes": {
            "first_name": null,
            "last_name": null,
            "email": "[email protected]"
        }
    }
}

//v1/users/ed526d56-cc7e-41f4-8e99-fccf73fb7500 should be /v1/users/ed526d56-cc7e-41f4-8e99-fccf73fb7500

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions