N
Nuxt2mo ago
wugge

RouteRules Exception for route path

Hi! I have a routeRule for my API like that:
'/api/**': 'http://my-api/**'
'/api/**': 'http://my-api/**'
Now I'm experiencing the issue that some nuxt modules use the path
/api/_nuxt_[module]
/api/_nuxt_[module]
for themselves How can I add an exception to the API route for a certain route?
2 Replies
Cue
Cue2mo ago
You’ll want to proxy your api and disable proxy for said module endpoints, e.g.
'/api/_nuxt_icon/**': { proxy: false },
'/api/**': { proxy: 'http://my-api/**' }
'/api/_nuxt_icon/**': { proxy: false },
'/api/**': { proxy: 'http://my-api/**' }
IIRC there was a bug in nitro when doing this. I haven’t tested to see if this is still the case. Failing the above, I would suggest renaming your api endpoint in your application to avoid the conflicts, for example:
'/api/v1/**': { proxy: 'http://my-api/**' }
'/api/v1/**': { proxy: 'http://my-api/**' }
If neither of these are desirable, you can take the cumbersome route of configuring custom endpoints for each of the modules that use the api prefix. For example, with Nuxt icon you’d add the following in the config:
icon: {
localApiEndpoint: '/_nuxt_icon'
}
icon: {
localApiEndpoint: '/_nuxt_icon'
}
And so on…
wugge
wuggeOP2mo ago
Hey! Thanks for your reply, coincidentally I'm facing the issue with nuxt icon, but also did with nuxt content before the solution with "localApiEndpoint" works well, however I'd prefer the first solution. I can't set the "proxy" property to false though, I'm getting a type error. is this for a specific version maybe or has it been changed?
Want results from more Discord servers?
Add your server