Open
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();