nuxt-auth-sanctum
nuxt-auth-sanctum copied to clipboard
[Feature] Server API proxy
Is your feature request related to a problem? Please describe.
A lot of people prefer using routeRules to proxy their Nuxt requests to the remote API, but usually it has problems with passing headers/cookies and can result in unexpected behaviour.
Describe the solution you'd like
It would be nice to provide a collection of Nuxt server API routes that can be used instead of the remote server to handle this with full support of CSRF/Headers/cookies and other parameters to pass it from the client request and then back from the Laravel API.
It can be just one single route that proxies everything. However, that requires proper testing with different scenarios and possible user customisation.
This configuration should be optional since it won't work for CSR-only applications. Probably, we can reuse an approach used for globalMiddleware, which is not loaded if not enabled in the config.
Describe alternatives you've considered
Provide a complete guide on the usage of routeRules with a remote server.
Additional context
Related to:
- https://github.com/manchenkoff/nuxt-laravel-echo/issues/115
- https://github.com/manchenkoff/nuxt-auth-sanctum/issues/183
- https://github.com/manchenkoff/nuxt-auth-sanctum/issues/113
- https://github.com/manchenkoff/nuxt-auth-sanctum/issues/106
- https://github.com/manchenkoff/nuxt-auth-sanctum/issues/94
- https://github.com/manchenkoff/nuxt-auth-sanctum/issues/37
Could you provide an optional middleware? :)
I'm new with Nuxt, I know you can with Laravel.
Thanks again for your help. I try to create a public repository with examples soon how I did it. See https://github.com/manchenkoff/nuxt-laravel-echo/issues/115 for my current changes.
Could you provide an optional middleware? :)
Yes, route middleware can be optional since you use it on the specific pages via definePageMeta, unlike global middleware, which works on every route.
@manchenkoff I'm back to just use Caddy as proxy with a /service path (they share the same url). I could also go for a subdomain instead.
The problem seems to be that the ProxyRequest cannot set cookies. It would be cool, but I've tried everything and it was very frustrating.