启动UseRouting中间件
This commit is contained in:
parent
923839db18
commit
8a02e9c937
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -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());
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user