dotnet / dotnet/aspnetcore

Provide HttpContext to baseUriTaskFactory in UseProxyToSpaDevelopmentServer

Open
#44,025 2 comments 2 reactions 0 assignees View on GitHub
api-suggestion area-ui-rendering enhancement feature-spa
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

## Background and Motivation
This is a bit of a shot in the dark, since I found out that `UseProxyToSpaDevelopmentServer` is not the _recommended/default_ way anymore, but rather SPAs to be in front of the ASP.NET (in the way of the new SPA templates). And that this API might become obsolete and removed.

I've never had any issues with it, so thank you for what you've been doing in the past!

I need to proxy to different URIs (known at runtime), depending on the request, to be more specific: depending on some items in `HttpClient.Items` set by other middlewares. The `baseUriTaskFactory` parameter description says the following:
`A callback that will be `**`invoked on each request`**` to supply a Task that resolves with the target base URI to which requests should be proxied.`
I want to actually access some information about **`each request`** in order to resolve the URI and currently the `baseUriTaskFactory` is a paremeterless function.

## Proposed API

```diff
namespace Microsoft.AspNetCore.Builder;

public static class SpaProxyingExtensions
{
+ public static void UseProxyToSpaDevelopmentServer(this ISpaBuilder spaBuilder, Func> baseUriTaskFactory)
}
```

## Usage Examples

Please provide code examples that highlight how the proposed API additions are meant to be consumed.
This will help suggest whether the API has the right shape to be functional, performant and useable.
You can use code blocks like this:
```csharp
spa.UseProxyToSpaDevelopmentServer((httpContext) => {
var somePort = httpContext.Items["somePort"];
return Task.FromResult(new Uri($"http://localhost:{somePort}/"));
})
```

Thanks!

Contributor guide

Open the contributing guide

Research direction

Start with the existing UseProxyToSpaDevelopmentServer API and the linked docs/APIReviewProcess.md. Review whether the proposed HttpContext callback fits the API's lifecycle and request-specific proxying needs; done means reaching an API-review decision on the proposal and its usage shape.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.