Unable to get domain routes working #4598
-
Hi, For several months I've been developing an application using AdonisJS (v5). My application is divided into three parts (back, admin, pwa). import Route from '@ioc:Adonis/Core/Route'
Route.group(() => {
/* Login */
Route.get('/login', './Front/SecurityController.login').as('auth.user.login') // Login
Route.post('/login', './Front/SecurityController.doLogin')
/* App */
Route.group(() => {
Route.get('/home', './Front/HomeController.index').as('home') // Home
Route.get('/users/:slug', './Front/UsersController.show').as('users.show') // Users
})
.as('front')
.middleware('auth:user')
}).domain('pwa.myapp.local') This is a very simplified example of my route.ts file, but the tests were made with this version. If I run the command GET|HEAD pwa.myapp.local/login ───── auth.user.login › ./Front/SecurityController.login
POST pwa.myapp.local/login ───────────────────── ./Front/SecurityController.doLogin
GET|HEAD pwa.myapp.local/home ─────────────── front.home › ./Front/HomeController.index
GET|HEAD pwa.myapp.local/users/:slug ── front.users.show › ./Front/UsersController.show 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: If I go to http://pwa.myapp.local/login, the page is displayed... Have I forgotten to do something? Is adding the In case the problem was with nested groups, I tried another approach, but the result was the same: import Route from '@ioc:Adonis/Core/Route'
/* Login */
Route.get('/login', './Front/SecurityController.login').as('auth.user.login').domain('pwa.myapp.local') // Login
Route.post('/login', './Front/SecurityController.doLogin').domain('pwa.myapp.local')
/* App */
Route.group(() => {
Route.get('/home', './Front/HomeController.index').as('home') // Home
Route.get('/users/:slug', './Front/UsersController.show').as('users.show') // Users
})
.as('front')
.domain('pwa.myapp.local')
.middleware('auth:user') Does anyone know what the problem is? Thanks in advance and see you soon. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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.
Hey @BenDavidson90! 👋🏻
Since you are using a domain, you have to specify the domain when generating the route.
📚 https://v5-docs.adonisjs.com/guides/routing#lookup-inside-a-domain