-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nudging tuyau to the location of controllers #8
Comments
How do you define your routes? In what files + via what kind of import? If possible a reproduction would be super helpful |
hey Julien thanks for the quick reply and sure thing will create a reproduction soon |
Hey Julien 👋 please find the reproduction below, also many thanks for you and the team for making this, I'm new to adonisjs and I like a lot about it but the type safety to inertia has been a big annoyance, so many thanks again 🙏 |
Thank you very much for reproducing the issue Here's the problem: try running [
// ....
{
"name": "",
"pattern": "/some-thing",
"methods": [
"GET"
],
"handler": {
"type": "controller",
"moduleNameOrPath": "../controllers/index.js",
"method": "index"
},
"middleware": []
}
] As you can see, the path to the controller is relative from the file where you defined your route, meaning: I hope that makes sense. There might potentially be a patch that can be applied to Now, the workaround I can suggest is to use subpath imports to register your routes: import router from '@adonisjs/core/services/router'
const SomeController = () => import('#my-module/controllers/someControllers')
function someModuleRoutes() {
router.get('/some-thing', [SomeController, 'index'])
}
export default someModuleRoutes Of course, don't forget to register this subpath import in your |
Hi ! In my project, I want to change the file structure to organize the code by functionality. Before doing so, I wanted to test if tuyau support modified paths. So I took this adonis starter who use this type of structure "by module" : https://github.com/batosai/adonis-starter-kit/tree/main in which I installed tuyau and followed your recommendations in this issue using subpaths imports but I have the same problem, tuyau can't find the controllers. In the package.json I've even specifically specified the path for each controller of the auth module to test and it doesn't work. Here is the repoduction link : https://github.com/Benjamin-htr/reproduction_tuyau_bug Maybe I missed something? EDIT :: I was doing that : # package.json
...
"imports": {
"#auth/start/*": "./src/auth/start/*.js",
"#auth/controllers/session_controller": "./src/auth/app/controllers/session_controller.js",
"#auth/controllers/forgot_password_controller": "./src/auth/app/controllers/forgot_password_controller.js",
"#auth/controllers/reset_password_controller": "./src/auth/app/controllers/reset_password_controller.js",
"#auth/controllers/impersonates_controller": "./src/auth/app/controllers/impersonates_controller.js",
"#auth/policies/*": "./src/auth/app/policies/*.js",
"#auth/mails/*": "./src/auth/app/mails/*.js",
"#auth/middleware/*": "./src/auth/app/middleware/*.js",
"#auth/validators/*": "./src/auth/app/validators/*.js",
...
},
... AND # src/auth/start/routes.ts
...
const SessionController = () => import('#auth/controllers/session_controller')
const ForgotPasswordController = () => import('#auth/controllers/forgot_password_controller')
const ResetPasswordController = () => import('#auth/controllers/reset_password_controller')
const ImpersonatesController = () => import('#auth/controllers/impersonates_controller')
... But by doing this, it works : # package.json
...
"imports": {
"#auth/*": "./src/auth/*.js",
...
},
... and : # src/auth/start/routes.ts
...
const SessionController = () => import('#auth/app/controllers/session_controller')
const ForgotPasswordController = () => import('#auth/app/controllers/forgot_password_controller')
const ResetPasswordController = () => import('#auth/app/controllers/reset_password_controller')
const ImpersonatesController = () => import('#auth/app/controllers/impersonates_controller')
... I think tuyau need the fullpath inside the lazy loading to find the path |
However, I'd like to help improve the internal workings of |
I'm using module base folder structure and it's seems tuyau can't find the controllers, is there is a way to nudge tuyau on where to look for the controllers?
The text was updated successfully, but these errors were encountered: