-
Notifications
You must be signed in to change notification settings - Fork 656
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
localhost, being used by so many different things, can get clogged up with cookies causing HTTP 431 "Request Header Fields Too Large" errors.
Additionally, it's not always possible to test or catch certain issues when everything uses localhost. CORS errors for example.
Describe the solution you'd like
I'd like Microsoft or the Aspire team to register a domain name specifically for Aspire to use with local development.
For the sake of my examples below, lets say you register aspire.dev
.
You would then create a wildcard DNS A record *.aspire.dev
pointing to 127.0.0.1
and an AAAA record *.aspire.dev
pointing to ::1
.
Within Aspire when running the apphost locally, you would then have it create all endpoints that would have been localhost using subdomains of aspire.dev instead.
For example:
var builder = DistributedApplication.CreateBuilder(args);
var databasePassword = builder.AddParameter("DatabasePassword", true);
var db = builder.AddPostgres("Database", password: databasePassword)
.WithHealthCheck()
.WithDataVolume($"AppHost-{Enum.GetName(databaseType)}-{name}-data")
.WithPgAdmin()
.AddDatabase("myApp");
builder.AddProject<Projects.Application_Host_Api>("MyApi")
.WithExternalHttpEndpoints()
.WithReference(db, dbOptions.ConnectionStringName)
.WaitFor(db);
The above apphost would create the following endpoints:
- Database:
- tcp - tcp://database.aspire.dev:54895 (port set as before)
- Database-pgadmin:
- MyApi:
- http - http://my-api.aspire.dev:5260/swagger (note kebab-casing from PascalCasing)
- https - http://my-api.aspire.dev:7285/swagger
If more randomness is needed to avoid naming collisions, a simple 4-6 character random string could be added. e.g. http://my-api-dfghas.aspire.dev:7285/swagger
As a stretch goal, you could also add the option to configure your own base domain for this, which would allow developers and organisations to use Hosts file entries or internal corporate DNS servers to have the same functionality without needing to do a DNS lookup across the internet (for those with more stringent security requirements)
Additional context
Lando, another docker-based local development tool for PHP, does this already. When spinning up local environments using Lando it uses subdomains of lndo.site
which has a 127.0.0.1 wildcard A record.
https://mxtoolbox.com/SuperTool.aspx?action=a%3aadfkljlgkh.lndo.site&run=toolpage