Nitro layers #2784
Exotelis
started this conversation in
Help Wanted
Nitro layers
#2784
Replies: 1 comment
-
I give you respect for your adventure. At this point, scanServerRoutes may be the answer, but it has a deprecated flag and only exists at build or runtime. The function cannot be called in the config file. Plus at this point nitro's layer doesn't register all plugins, middleware, and routes into the app system. In a nutshell, it doesn't work. It doesn't seem to have been added to the roadmap. I hope it develops someday. I think if nitro currently only has the capabilities for layer and dependency infusion, it will be mature enough to switch from nestjs. |
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
-
After #2508 was closed and I actually wanted to use modules to add endpoints to an existing BFF, @pi0 pointed out, that layers are a better alternative to modules. These are supposed to work similarly to Nuxt layers.
However, after some initial attempts, I immediately noticed differences in the behavior of Nitro layers compared to Nuxt layers. And since layers in Nitro are still a hidden feature (there’s no documentation for them), I’ve only been able to experiment so far.
What doesn’t work are auto imports - both the auto import of functions as well as the auto import of routes. When I use my layer app in a host app, the endpoints simply aren’t present. The runtimeConfig, however, is applied correctly. I created an example on Stackblitz.
After going through the docs, types and the source code, I found out that you can solve the problem using handlers in the nitro.config. However, this of course means losing one of the best features - ideally, I wouldn’t want to define routes manually. Additionally, you have to resolve the paths accordingly. The functions such as
defineEventHandler
, oruseRuntimeConfig
must be imported from#imports
. I also prepared this as an example.Is there already a solution for this, can I define a resolver to automatically add handlers? Ofc I could manually parse the src folder, but I would have to do this in any layer I add.
Also, it would be great to have a utility function that retrieves all the defined routes in the host app, or even another layer. For instance, if layerA adds the route
/layerA
and layerB adds/layerB
, it would be fantastic to generate a list of all the routes.Beta Was this translation helpful? Give feedback.
All reactions