2
0
Эх сурвалжийг харах

启动UseRouting中间件

xljiulang 4 жил өмнө
parent
commit
8a02e9c937

+ 3 - 4
FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs

@@ -23,13 +23,12 @@ namespace FastGithub
         /// <summary>
         /// 使用https反向代理中间件
         /// </summary>
-        /// <param name="app"></param>
-        /// <param name="fallbackFile"></param>
+        /// <param name="app"></param> 
         /// <returns></returns>
-        public static IApplicationBuilder UseHttpsReverseProxy(this IApplicationBuilder app, string fallbackFile)
+        public static IApplicationBuilder UseHttpsReverseProxy(this IApplicationBuilder app)
         {
             var middleware = app.ApplicationServices.GetRequiredService<ReverseProxyMiddleware>();
-            return app.Use(next => context => middleware.InvokeAsync(context, fallbackFile));
+            return app.Use(next => context => middleware.InvokeAsync(context, next));
         }
     }
 }

+ 3 - 4
FastGithub.ReverseProxy/ReverseProxyMiddleware.cs

@@ -33,15 +33,14 @@ namespace FastGithub.ReverseProxy
         /// 处理请求
         /// </summary>
         /// <param name="context"></param>
-        /// <param name="fallbackFile"></param>
+        /// <param name="next"></param>
         /// <returns></returns>
-        public async Task InvokeAsync(HttpContext context, string fallbackFile)
+        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
         {
             var host = context.Request.Host.Host;
             if (this.fastGithubConfig.TryGetDomainConfig(host, out var domainConfig) == false)
             {
-                context.Response.ContentType = "text/html";
-                await context.Response.SendFileAsync(fallbackFile);
+                await next(context);
             }
             else if (domainConfig.Response != null)
             {

+ 10 - 2
FastGithub/Program.cs

@@ -1,4 +1,6 @@
-using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Http;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Hosting;
@@ -54,7 +56,13 @@ namespace FastGithub
                     web.Configure(app =>
                     {
                         app.UseRequestLogging();
-                        app.UseHttpsReverseProxy("README.html");
+                        app.UseHttpsReverseProxy();
+                        app.UseRouting();
+                        app.UseEndpoints(endpoints => endpoints.Map("/", async context =>
+                        {
+                            context.Response.ContentType = "text/html";
+                            await context.Response.SendFileAsync("README.html");
+                        }));
                     });
                     web.UseKestrel(kestrel => kestrel.ListenHttpsReverseProxy());
                 });