0

I have tried valet link api.domain but it shows 502 Bad Gateway. My folder structure is basically very simple. I am using valet park on ~/Sites and there is a backend and frontend folder in that ~/Sites directory. I basically want to access api.domain.test and spa.domain.test instead of backend.test and frontend.test.

The reason is using Laravel Sanctum with XSRF cookie protection. The domain + TLD must be same for the cookies to work. I have also tried valet proxy but that only worked properly for frontend.test being mapped to localhost:3000 where I serve my Next.js. Any help would be appreciated. Thanks.

Ali Gajani
  • 14,762
  • 12
  • 59
  • 100

1 Answers1

1

Have you tried the following

cd ~/Sites/backend

valet link api.domain
cd ~/Sites/frontend

valet link spa.domain

valet proxy spa.domain http://127.0.0.1:3000
Donkarnash
  • 12,433
  • 5
  • 26
  • 37
  • Doing so does not resolve the issue as now both ```api.domain.test``` and ```spa.domain.test``` both are pointing to the ```frontend.test``` – Muhammad Yasir Aug 09 '22 at 03:22
  • @MuhammadYasir How do you conclude that both `api.domain.test` and `spa.domain.test` both point to `frontend.test`? `api.domain.test` & `backend.test` will serve from `~/Sites/backend` while `spa.domain.test` & `frontend.test` will serve from `~/Sites/frontend` – Donkarnash Aug 09 '22 at 19:37
  • Upon adding the proxy for ```spa.domain.test``` to point to the ```http://127.0.0.1:3000``` the Valet is transferring traffic from all wild card subdomains of ```domain.test``` like ```api.domain.test```, ```spa.domain.test``` and ```foo.domain.test``` to ```frontend.test``` – Muhammad Yasir Aug 10 '22 at 12:33
  • @MuhammadYasir Proxy for **spa.domain.test** to point to `http://127.0.0.1:3000` would be proxying traffic to a particular port `3000` in this case while normally the http traffic is via port **80** and **443** is what I understand. So proxying to a particular port should not transfer all wild card traffic is what I guess. I'm not very conversant with the proxying stuff so please let me know if my understanding is correct or otherwise. – Donkarnash Aug 10 '22 at 19:41
  • 1
    I encountered the same issue that both URLs point to the frontend. You'll need to check if the proxies and links are point correctly. `valet proxies` `valet links` The order might be important also. Proxy first before Link. – Jerico Pulvera Aug 11 '22 at 06:49
  • @JericoPulvera You can see in my question that proxy and links are pointing to right directories https://stackoverflow.com/questions/73286361/using-valet-to-serve-two-projects-on-sub-domains-using-proxy – Muhammad Yasir Aug 14 '22 at 04:54
  • You should only have 1 link and 1 proxy. You should unlink the app valet unlink app.nuxtodo – Jerico Pulvera Aug 14 '22 at 09:47