[Rails6:EN] Subdomain constraint not working
tacataca opened this issue · 1 comments
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:
- 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 yourdevelopment.rb
environment file.
With this you can runcurl http://api.lvh.me:3000/users/1
- Alternatively add a section on editing the system hosts file.
Hi,
First of all thanks YOU for this report and your PR.
I fact this is a modification between version 5 and 6. In version 5, I setup a API host as http://api.localhost:3000/users/1. In version 6 I preferred to simplify book so I setup host URL as something like this http://localhost:3000/api/v1/users/1.
This allow me some explanation about host configuration and local environement setup who may disappoint newbies.
Setting the API under a subdomain is a good practice because it allows the application to be adapted to a DNS level. But we will simplify things for now in our case.
I corrected error directly in the book on 792a922
Thank you for this report.