C
C#6d ago
Greenthy

Aspire YARP custom domain instead of localhost

I have a legacy solution which we are migrating from IIS to aspire (after upgrading to dotnet 8). Our solution relies on hosting on a single domain, so to ensure this we've added a YARP project to do the necessary reverse proxying from the different projects. This works well, and we are able to navigate to for instance the swagger pages. As mentioned though, we rely on running behind a custom domain, which we added to our host file. However we cannot seem to get the custom domain working on the aspire YARP project. We've tried https://anthonysimmon.com/dotnet-aspire-non-localhost-endpoints/ but this only adds the custom domain in the dashboard. We appear to need to hook it up into the yarp project. But we can't seem to find the correct info on how to do this. (And potentially also how to 'terminate' HTTPS on YARP) Any help is greatly appreciated.
Anthony Simmon
Use non-localhost endpoints for .NET Aspire resources
Learn how to use custom hosts instead of localhost for .NET Aspire resources during local development with or without a reverse proxy.
6 Replies
Greenthy
GreenthyOP6d ago
YARP config is basicly: Routeconfig:
C#
new RouteConfig()
{
RouteId = RouteName(config),
ClusterId = ClusterName(config),
Match = new RouteMatch()
{
Path = config.Path.TrimEnd('/') + "/{**catchall}"
},
Transforms = new List<Dictionary<string, string>>()
{
new() { { YarpTransforms.PathRemovePrefix, config.Path.TrimEnd('/') } }
}
};
C#
new RouteConfig()
{
RouteId = RouteName(config),
ClusterId = ClusterName(config),
Match = new RouteMatch()
{
Path = config.Path.TrimEnd('/') + "/{**catchall}"
},
Transforms = new List<Dictionary<string, string>>()
{
new() { { YarpTransforms.PathRemovePrefix, config.Path.TrimEnd('/') } }
}
};
Clusterconfig:
C#
return new ClusterConfig()
{
ClusterId = ClusterName(config),
Destinations = new Dictionary<string, DestinationConfig>()
{
{
DestinationName(config),
new DestinationConfig()
{
Address = config.BackendUrl,
}
}
}
};
C#
return new ClusterConfig()
{
ClusterId = ClusterName(config),
Destinations = new Dictionary<string, DestinationConfig>()
{
{
DestinationName(config),
new DestinationConfig()
{
Address = config.BackendUrl,
}
}
}
};
with the backendUrl http://api1 etc... . yarp program.cs:
c#
builder.Services
.AddServiceDiscovery()
.AddReverseProxy()
.LoadFromMemory(...)
.AddServiceDiscoveryDestinationResolver();
c#
builder.Services
.AddServiceDiscovery()
.AddReverseProxy()
.LoadFromMemory(...)
.AddServiceDiscoveryDestinationResolver();
aspire:
c#
var gateway = builder.AddProject<Projects.ApiGateway>("gateway")
.WithHttpsEndpoint(port: 443)
.WithReverseProxyEndpoint("app-dev", "https://app-dev.myapp.com")
.WithReference(api1)
.WithReference(api2)
.WithReference(apiclient);
c#
var gateway = builder.AddProject<Projects.ApiGateway>("gateway")
.WithHttpsEndpoint(port: 443)
.WithReverseProxyEndpoint("app-dev", "https://app-dev.myapp.com")
.WithReference(api1)
.WithReference(api2)
.WithReference(apiclient);
api1 and api2 are net8 minimal api's, apiclient an angular spa
Unknown User
Unknown User6d ago
Message Not Public
Sign In & Join Server To View
Greenthy
GreenthyOP6d ago
https://github.com/kvloover/CustomDomainAspire Sadly this slimmed down version appears to be working, I'll try investigating if I properly cleaned up the IIS part i guess
GitHub
GitHub - kvloover/CustomDomainAspire
Contribute to kvloover/CustomDomainAspire development by creating an account on GitHub.
Greenthy
GreenthyOP5d ago
well aside from not providing the certificate ofc Having a bit of silly trouble hosting the cert though. Ive tried setting the kestrel endpoints variable, but it needs an url. I don't know which url to pass as it's dynamically created by aspire
Unknown User
Unknown User5d ago
Message Not Public
Sign In & Join Server To View
Greenthy
GreenthyOP4d ago
not really following there, but for now I'm just going to stick to localhost till I find the courage to deep dive into this again

Did you find this page helpful?