dotnet / dotnet/aspnetcore

Spa Proxy Middleware not configurable

Open
#59,807 1 comment 5 reactions 0 assignees View on GitHub
area-mvc
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

Given two Applications A and B, where A is an old .NET Framework web application and application B is a .NET 8 web application with web routes and the recommended SPA setup (React.js) using the SPA proxy for the development setup and integration with Vite. So application A sits in front of application B in the production deployment and is hosting the SPA at an arbitrary URL, lets say `/spa`. Application A runs on port `10000` and B on `10001`. Application is configured with YARP to forward non-found rounds to application B. This works flawlessly.

During the development setup, the SPA is hosted via Vite, let us say port `10002`. When now calling application A directly, it forwards via the `` in `.csproj` to the SPA which in itself proxies web requests from the SPA back to application A. This all works as intended so far.

The issue is, this only works for working in the spa, so all web browser calls directly to application A on port `10001` end up being redirected to `:10002/spa`, but I would like to work on "old" frontend pages at e.g. `:10000/` too (which proxies to application B), which is not possible due to the always redirect.

### Describe the solution you'd like

The current implementation at https://github.com/dotnet/aspnetcore/blob/main/src/Middleware/Spa/SpaProxy/src/SpaProxyStartupFilter.cs is internal, even the options. This means, there is zero room for adjusting anything. A simple approach would be to make these public, then we developers can at least swap out parts of the default implementation without rewriting all parts.

For the above issue, a path exclusion list would solve the issue, or even better, whitelisting: Only redirect `10000:/spa` calls to Vite, no other routes. A better solution would be to either expose some `UseProxySpa(configure => ...)` middleware with the ability to configure the options or even write custom rules for when to redirect and when not.

### Additional context

There is almost no documentation regarding the `Microsoft.AspNetCore.SpaProxy` package or what it does. So if you do not stumble across it via a template or. by looking at the source code, you either do not know that it exists at all or it works with too much magic. There was some documentation regarding the SpaProxy which I can see in Googles cache, but when opening https://learn.microsoft.com/en-us/aspnet/core/client-side/spa/intro?view=aspnetcore-9.0 it only holds very basic information.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.