Skip to content

UseUrls equivilant API for Http and Https ports #44772

Open
@Tratcher

Description

@Tratcher

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.

#43135 (comment)

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

No one assigned

    Labels

    Needs: DesignThis issue requires design work before implementating.api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions