using FastGithub.ReverseProxy; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Yarp.ReverseProxy.Forwarder; namespace FastGithub { /// /// gitub反向代理的中间件扩展 /// public static class ReverseProxyApplicationBuilderExtensions { /// /// 使用gitub反向代理中间件 /// /// /// public static IApplicationBuilder UseGithubReverseProxy(this IApplicationBuilder app) { var httpForwarder = app.ApplicationServices.GetRequiredService(); var httpClient = app.ApplicationServices.GetRequiredService(); app.Use(next => async context => { var hostString = context.Request.Host; var port = hostString.Port ?? 443; var destinationPrefix = $"http://{hostString.Host}:{port}/"; await httpForwarder.SendAsync(context, destinationPrefix, httpClient); }); return app; } } }