-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement --reverse-proxy <SOURCE_PATH_PATTERN>=<DESTINATION_URL_PREFIX>
#85
Conversation
Codecov Report
@@ Coverage Diff @@
## main #85 +/- ##
==========================================
+ Coverage 24.02% 27.19% +3.16%
==========================================
Files 17 17
Lines 541 603 +62
==========================================
+ Hits 130 164 +34
- Misses 411 439 +28
Continue to review full report at Codecov.
|
Hi, did you get a chance to take a look? I'm in no rush of course. I just think it would be a nice addition to this project, especially since this feature has been requested by others in the past... |
Thanks for proposing this improvement. I would like to wait until Yarp releases a stable version before incorporating it into this project. My experience in the past has been that you can't rely on previews of .NET projects for production-ready code. Once there is a stable release, I would be happy to add the reverse proxy feature. Side note: as a matter of preference, I would like to keep PRs focused on a single thing. If you think this project needs cleanup or needs to drop the .NET Core 2 support, can you do those as separate pull requests? Thanks for your effort here. I am glad you decided to contribute! |
Also, I see some of the workflow checks on this PR are failing. I won't merge a change unless it passes all tests. Can you check the reason why and make changes if necessary? |
Alright, I can get behind that.
I agree with you, but since Yarp does not support .NET Core 2.1, removing support for .NET Core 2.1 is part of the changes required to add Yarp... (As I said, it would be possible to add lots of #ifdefs instead, but I don't really see the point if we are going to remove them immediately after)
I believe the CI is broken for other reasons than my PR:
It seems this is a known issue, and there is a workaround: actions/setup-dotnet#155 (comment) I can try to fix it in another PR if you wish... |
Removing .NET Core 2 can be done separately. I would be okay taking that change first before adding Yarp later this year when it releases a stable version |
.NET Core 2 has been dropped, btw... |
Hello, thanks for the heads-up! |
5fe3e02
to
3a321aa
Compare
The PR should be ok to review now. |
Did you consider taking advantage of the APIs that YARP already provides for managing HTTP clients and forwarding? From reading the sample in https://github.com/microsoft/reverse-proxy/tree/main/samples/BasicYarpSample and https://microsoft.github.io/reverse-proxy/articles/config-providers.html, I got the impression that the code would look much more like this: if (_options.HasReverseProxyMappings)
{
// Enable endpoint routing, required for the reverse proxy
app.UseRouting();
// Register the reverse proxy routes
app.UseEndpoints(endpoints =>
{
endpoints.MapReverseProxy();
});
} And then we could implement something like https://github.com/microsoft/reverse-proxy/blob/main/samples/ReverseProxy.Code.Sample/InMemoryConfigProvider.cs (see also https://microsoft.github.io/reverse-proxy/articles/config-providers.html). Thoughts? |
The sample you linked to is short because all the proxy configuration is read from a config file with a structure controlled and known by YARP. The in-memory config example is even more complex since we have to maintain both the in-memory configuration provider implementation and the actual proxy configuration in Startup.cs using this provider. The nice I instead followed the Direct Forwarding approach that seems to be more appropriate for our use case (we currently have no use for advanced features like clustering and load balancing). I think starting with a simple |
Ok, thanks for the explanation. Let's give this a try! Thanks for the contribution 😄 |
I would like to use
dotnet-serve
as a convenient and easy way to setup a Fable development environment while staying in the .NET world, and one thing that is missing is a reverse proxy feature so I can quickly iterate on the frontend while keeping a backend api running separately.I saw that I'm not the first to want a reverse proxy (#11), but it looks like the last person lost interest...
This PR implements a
--reverse-proxy <SOURCE_PATH_PATTERN>=<DESTINATION_URL_PREFIX>
directive, using https://github.com/microsoft/reverse-proxy (YARP)It seems to work great, and was easy enough to implement, even though YARP is still in preview.
One drawback is that YARP does not support .NET Core 2.1, so its support in dotnet-serve would have to be dropped. (Or we would need to add lots of
#if NETCOREAPP2_1
)I'm not sure it's a big problem: after all
dotnet-serve
is a tool, so it's likely to be run on up-to-date versions of .NET don't you think?I added some unit tests for the configuration and for the feature itself.
I cleaned up existing
#if NETCOREAPP2_1
in a separate commit since I wasn't sure you were ready to drop its support completely. If you absolutely want to keep this target, I could drop this commit and wrap all the reverse proxy related stuff in new#if NETCOREAPP2_1
instead (please don't make me do that).Tell me what you think! :)