From 8a02e9c9372f4fb4295ff6998270aeb2e3656a1f Mon Sep 17 00:00:00 2001
From: xljiulang <366193849@qq.com>
Date: Sun, 25 Jul 2021 00:20:32 +0800
Subject: [PATCH] =?UTF-8?q?=E5=90=AF=E5=8A=A8UseRouting=E4=B8=AD=E9=97=B4?=
=?UTF-8?q?=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ReverseProxyApplicationBuilderExtensions.cs | 7 +++----
FastGithub.ReverseProxy/ReverseProxyMiddleware.cs | 7 +++----
FastGithub/Program.cs | 12 ++++++++++--
3 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs b/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs
index d785172..79f6996 100644
--- a/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs
+++ b/FastGithub.ReverseProxy/ReverseProxyApplicationBuilderExtensions.cs
@@ -23,13 +23,12 @@ namespace FastGithub
///
/// 使用https反向代理中间件
///
- ///
- ///
+ ///
///
- public static IApplicationBuilder UseHttpsReverseProxy(this IApplicationBuilder app, string fallbackFile)
+ public static IApplicationBuilder UseHttpsReverseProxy(this IApplicationBuilder app)
{
var middleware = app.ApplicationServices.GetRequiredService();
- return app.Use(next => context => middleware.InvokeAsync(context, fallbackFile));
+ return app.Use(next => context => middleware.InvokeAsync(context, next));
}
}
}
diff --git a/FastGithub.ReverseProxy/ReverseProxyMiddleware.cs b/FastGithub.ReverseProxy/ReverseProxyMiddleware.cs
index 4429472..195db6b 100644
--- a/FastGithub.ReverseProxy/ReverseProxyMiddleware.cs
+++ b/FastGithub.ReverseProxy/ReverseProxyMiddleware.cs
@@ -33,15 +33,14 @@ namespace FastGithub.ReverseProxy
/// 处理请求
///
///
- ///
+ ///
///
- 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)
{
diff --git a/FastGithub/Program.cs b/FastGithub/Program.cs
index 61ac886..e9c6707 100644
--- a/FastGithub/Program.cs
+++ b/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());
});