启动UseRouting中间件

This commit is contained in:
xljiulang 2021-07-25 00:20:32 +08:00
parent 923839db18
commit 8a02e9c937
3 changed files with 16 additions and 10 deletions

View File

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

View File

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

View File

@ -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.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
@ -54,7 +56,13 @@ namespace FastGithub
web.Configure(app => web.Configure(app =>
{ {
app.UseRequestLogging(); 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()); web.UseKestrel(kestrel => kestrel.ListenHttpsReverseProxy());
}); });