I'm upgrading a solution containing several web apps from .net framework to .net 8.
I'm running into problems setting up the Kestrel development server. It was really easy to do with IIS Express: just map each app to a different relative path.
The solution I've tried is using YARP to route requests to the relative paths, and this is monumentally difficult to setup and fragile in practice.
In the past, I had the two apps running at https://localhost:1000/foo and https://localhost:1000/bar.
Now, I come across the idea of setting them up on https://localhost:1001 and https://localhost:1002, respectively, and then using YARP to route requests from https://localhost:1000/foo and https://localhost:bar to https://localhost:1001 and https://localhost:1002, respectively.
It sounds relatively simple in theory, but in practice, I experience requests to static files, API endpoint, and Javascript being misrouted.
For example (and this is just one example), I have a web page at https://localhost:1000/foo called index.html and it references a script foo.js.
I would normally reference that with <script src="~/foo.js"></script>
. Normally, under IIS Express, the URL would be rendered as https://localhost:1000/foo/foo.js, but now it's getting rendered as https://localhost:1000/foo.js, and it no longer matches the correct route and results in a 404 error.
Is there a better solution than simply setting up YARP and trying to delicately balance all the different ways that every single resource could get routed?
I would suggest you not remove subpath when you are doing route, it's better when application knows they work in sub path, so as you mention it will generate correct path when generating responses.
It should look like
localhost:1000/foo
should be routed to localhost:1001/foo
localhost:1000/bar
should be routed to localhost:1002/bar
It's a common issue when more then one app working behind some proxy, I wrote about it in something about it here in way#2 there was description based on app AgroCD also to resolve this problem many other apps support it like Sonarqube using using env variable SONAR_WEB_CONTEXT.
ASP.NET to make this thing easier provide something called PathBase
so you can use app.UsePathBase("/foo");
(but still when your generated any link in response content you need to add it manually).
In Blazor you can use <base href="@(Program.PathBase)/" />
to correctly generate links