microeinhundert / radonis

Build monolithic applications with a modern, React-based frontend stack based on the Node.js MVC framework AdonisJS.
https://radonis.vercel.app/
MIT License
67 stars 2 forks source link

Form component + subdomain route causes "Error [Radonis] Cannot find route for AuthController.login" #4

Closed finestgecko closed 1 year ago

finestgecko commented 2 years ago

I'm building a multi-tenant application, where each tenant has a subdomain. I use a route group for this.

The routes look like this:

Route.group(() => {
  Route.get('/auth/login', 'AuthController.showLogin')
  Route.post('/auth/login', 'AuthController.login')
})
  .domain(`:tenant.${Env.get('BASE_TENANT_SUBDOMAIN')}`)
  //.middleware(['tenant'])

I'm using the form component:

<Form method="post" action="AuthController.login" reloadDocument>
    ...
</Form>

When I visit http://<tenant>.dev.local/auth/login, I get this error in the browser:

Error
[Radonis] Cannot find route for "AuthController.login"
node_modules/@microeinhundert/radonis-shared/build/cjs/src/utils.js:26:11                  invariant
node_modules/@microeinhundert/radonis-hooks/build/cjs/src/hooks/useUrlBuilder.js:28:40                  findRouteOrFail
node_modules/@microeinhundert/radonis-hooks/build/cjs/src/hooks/useUrlBuilder.js:88:23                  Object.make
node_modules/@microeinhundert/radonis-form/build/cjs/src/hooks/useForm.js:46:43                  useForm
node_modules/@microeinhundert/radonis-form/build/cjs/src/components/Form.js:19:40                  Form
node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5662:16                  renderWithHooks

I also tried action="/auth/login" but got the same error. Looking at the types, it seems like only the route identifier is applicable here.

If I comment out the form, it works as expected.

Looking at the stack trace, then referring to findRouteOrFail:

https://github.com/microeinhundert/radonis/blob/e3d02a1a7c0264446c1b8131c8b5e18b5cdc718c/packages/radonis-hooks/src/hooks/useUrlBuilder.ts#L22

It seems the routes are coming from the manifest, so I will include that here:

{
  "entry.client": {
    "type": "entry",
    "path": "/radonis/entry.client.js",
    "flashMessages": [],
    "messages": [],
    "routes": [
      "action",
      "formAction",
      "to",
      "auto"
    ],
    "imports": []
  }
}

(it's the same regardless of whether I uncomment .domain() or not)

At the moment, I'm still figuring out how things work, but would love to start contributing once I'm a bit more familiar with the codebase.

microeinhundert commented 2 years ago

I'm afraid multi tenancy is currently not supported, only the root routes are loaded.

https://github.com/microeinhundert/radonis/blob/09d4233abe56fa0e6a490800fd15e7f08f8950dd/packages/radonis-server/src/utils/extractRootRoutes.ts#L16-L27

The manifest file is only required for components, as these can run client-side. Everything outside of a component is not included in the manifest, because everything is available on the server anyway.

finestgecko commented 2 years ago

@microeinhundert Do you think support for subdomains is something that could be considered for the roadmap?

microeinhundert commented 2 years ago

Yes this could be implemented in the future, but currently there are features I want to implement first. Since this is just a hobby project and my first try at Open Source, I can't say for sure when this feature will be implemented.