Skip to content

[Rails6:EN] Subdomain constraint not working #6

@tacataca

Description

@tacataca

Hi, first of all thanks for working on updating this tutorial.

I have been trying to follow the rails 6 version and on chapter 3, when testing via the api for the first time via curl, I noticed 2 issues:

  • The path is incorrect (if using the constraint), its listed as /api/v1/users/1 while it should be /users/1
  • The subdomain constraint isn't working because doing something like curl http://api.localhost:3000/users/1 is invalid (unless you define api.localhost on your hosts file)

What I would suggest to be able to use the subdomain constraint on local development is:

  1. Use lvh.me which resolves itself plus any subdomain to localhost (without user requiring to change anything on their system). For rails 6, you would just need to add config.hosts << "api.lvh.me" somewhere in your development.rb environment file.
    With this you can run curl http://api.lvh.me:3000/users/1
  2. Alternatively add a section on editing the system hosts file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions