Unable to get domain routes working #4598
Unanswered
BenDavidson90
asked this question in
Help
Replies: 1 comment
-
Hey @BenDavidson90! 👋🏻 Since you are using a domain, you have to specify the domain when generating the route. Route
.get('/users/:id', 'UsersController.show')
.domain(':tenant.adonisjs.com')
// Make URL
const url = Route.makeUrl('UsersController.show', [1], {
domain: ':tenant.adonisjs.com',
}) 📚 https://v5-docs.adonisjs.com/guides/routing#lookup-inside-a-domain |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
For several months I've been developing an application using AdonisJS (v5). My application is divided into three parts (back, admin, pwa).
Until now I used http://127.0.0.1:3333/pwa to access my application.
Now that I have to put it into production, /back, /admin and /pwa will be replaced by https://pwa.myapp.com, http://back.myapp.com and https://admin.myapp.com.
In the documentation, it's written that you should use the
domain
parameter in the route.ts, which is what I've done (using myapp.local to test locally that it works):This is a very simplified example of my route.ts file, but the tests were made with this version.
If I run the command
node ace list:routes
it gives me:I've modified the host file on my Windows, restarted the server and on the browser I've typed http://pwa.myapp.local/home, which should return me to the login page as I'm not connected, but I get this error from AdonisJS:
E_CANNOT_FIND_ROUTE: Cannot find route for ‘auth.user.login’ identifier
.However, the route does appear on the
list:routes
!If I go to http://pwa.myapp.local/login, the page is displayed...
In my doLogin controller (which is called when the form is sent) I've added a
console.log(‘ok’)
.I enter my login, I validate, the ‘ok’ is displayed on the terminal, but I'm still located on /login (and not /home which should have appeared once the user had logged in) and I get this error:
E_CANNOT_FIND_ROUTE: Cannot find route for "front.home" identifier
, which again appear on thelist:routes
.Have I forgotten to do something? Is adding the
domain
parameter to the route.ts not enough?Why does it work by typing URLs directly, but calls from controllers (
return response.redirect().toRoute('front.home')
), Auth.ts (for redirect to login page if not logged) and templates ({{ route('front.home') }}
) throw an error?In case the problem was with nested groups, I tried another approach, but the result was the same:
Does anyone know what the problem is? Thanks in advance and see you soon.
Beta Was this translation helpful? Give feedback.
All reactions