-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Open
Labels
Needs: DesignThis issue requires design work before implementating.This issue requires design work before implementating.api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Milestone
Description
Background and Motivation
#44194 added config support in the host for mapping HTTP_PORTS and HTTPS_PORTS to URLS. @davidfowl suggested also adding an API for this on the host, similar to UseUrls.
Proposed API
Initial theories, needs work:
namespace Microsoft.AspNetCore.Hosting;
public static class HostingAbstractionsWebHostBuilderExtensions
{
+ public static IWebHostBuilder UseHttpPorts(this IWebHostBuilder hostBuilder, params int[] httpPorts);
+ public static IWebHostBuilder UseHttpsPorts(this IWebHostBuilder hostBuilder, params int[] httpsPorts);
+ public static IWebHostBuilder UsePort(this IWebHostBuilder hostBuilder, int port, bool useHttps);
+ public static IWebHostBuilder UsePorts(this IWebHostBuilder hostBuilder, int httpPort, int httpsPort);
}
Usage Examples
var port = int.Parse(Environment.GetEnvironmentVariable("PORT") ?? "3000");
var builder = WebApplication.CreateBuilder(args);
buider.WebHost.UsePort(port);
var app = builder.Build();
app.MapGet("/", () => "Hello World");
app.Run();
Alternative Designs
Risks
Metadata
Metadata
Assignees
Labels
Needs: DesignThis issue requires design work before implementating.This issue requires design work before implementating.api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions