microsoft / reverse-proxy

A toolkit for developing high-performance HTTP reverse proxy applications.

Home Page:https://microsoft.github.io/reverse-proxy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

YARP doesnt work on opening WebSockets towards .net UseProxyToSpaDevelopmentServer when the spa has live-reload enabled

muntdan opened this issue · comments

I have a YarpApi that has config paths for loading SPAs from another .net Api (lets call it SpaApi).
In debug mode I use in the SpaApi with the UseProxyToSpaDevelopmentServer to actually connect to the Angular process running on a different port.

YarpApi -> SpaApi -> Angular Live Development Server

Because the angular has the live-reload enabled after connecting to the Angular Spa there is a request
StatusCode: 101 | Upgrade: websocket
but in edge/chromium the request fails:
WebSocket connection to 'wss://localhost:1043/spaPath/ng-cli-ws' failed.
image

Documentation states no special config should be done for websockets:
https://microsoft.github.io/reverse-proxy/articles/websockets.html

Both .net api are Net 8 version and latest Yarp 2.1 and I am running this on Windows 11 | VS 2022 17.8.5

WebSockets shouldn't require anything special. Enable debug logs on each application to see if you can find any errors.

I did this and no trace of that request appears on neither of the 2 api.
I don't know if it has relevance but the first Yarp api in debug mode is run with https.

I found this demo by @davidfowl: https://github.com/davidfowl/YarpTunnelDemo.
Could this help or was this an old demo before the latest release of Yarp and now all of that is supposed to work already with latest Yarp ?

Can you provide a repro?

Hi, when I did the demo simple api repo I realized that it was the middleware for Spa Antiforgery with XSRF-TOKEN that was blocking those special requests without logging anything.
Thank you for your support !