Nitro layers #2784
Exotelis
started this conversation in
Help Wanted
Nitro layers
#2784
Replies: 0 comments
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