map fallback to github/fastgithub
This commit is contained in:
parent
1e67d8c5b9
commit
17f7959dbe
@ -60,25 +60,6 @@ namespace FastGithub.Configuration
|
||||
return GetAllIPAddresses().Contains(address);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有域名和ip
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static HashSet<string> GetAllHostNames()
|
||||
{
|
||||
var hashSet = new HashSet<string>
|
||||
{
|
||||
Name,
|
||||
"localhost",
|
||||
};
|
||||
|
||||
foreach (var address in GetAllIPAddresses())
|
||||
{
|
||||
hashSet.Add(address.ToString());
|
||||
}
|
||||
return hashSet;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取与远程节点通讯的的本机IP地址
|
||||
/// </summary>
|
||||
|
||||
@ -51,8 +51,8 @@ namespace FastGithub.Dns
|
||||
{
|
||||
var builder = new StringBuilder().AppendLine($"DNS服务启动失败({ex.Message}),你可以选择如下的一种操作:");
|
||||
builder.AppendLine($"1. 关闭占用udp53端口的进程然后重新打开本程序");
|
||||
builder.AppendLine($"2. 向系统hosts文件添加要加速的域名的ip为127.0.0.1");
|
||||
builder.AppendLine($"3. 配置系统或浏览器使用DNS over HTTPS:https://127.0.0.1/dns-query");
|
||||
builder.AppendLine($"2. 配置系统或浏览器使用DNS over HTTPS:https://127.0.0.1/dns-query");
|
||||
builder.AppendLine($"3. 向系统hosts文件添加github相关域名的ip为127.0.0.1");
|
||||
builder.Append($"4. 在局域网其它设备上运行本程序,然后将本机DNS设置为局域网设备的IP");
|
||||
this.logger.LogError(builder.ToString());
|
||||
}
|
||||
|
||||
@ -3,7 +3,6 @@ using FastGithub.Http;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Yarp.ReverseProxy.Forwarder;
|
||||
|
||||
@ -18,8 +17,6 @@ namespace FastGithub.ReverseProxy
|
||||
private readonly IHttpClientFactory httpClientFactory;
|
||||
private readonly FastGithubConfig fastGithubConfig;
|
||||
private readonly ILogger<ReverseProxyMiddleware> logger;
|
||||
private readonly HashSet<string> localHostNames = LocalMachine.GetAllHostNames();
|
||||
private readonly DomainConfig defaultDomainConfig = new() { TlsSni = true };
|
||||
|
||||
public ReverseProxyMiddleware(
|
||||
IHttpForwarder httpForwarder,
|
||||
@ -42,18 +39,11 @@ namespace FastGithub.ReverseProxy
|
||||
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
|
||||
{
|
||||
var host = context.Request.Host.Host;
|
||||
if (this.localHostNames.Contains(host) == true)
|
||||
{
|
||||
await next(context);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.fastGithubConfig.TryGetDomainConfig(host, out var domainConfig) == false)
|
||||
{
|
||||
domainConfig = this.defaultDomainConfig;
|
||||
await next(context);
|
||||
}
|
||||
|
||||
if (domainConfig.Response == null)
|
||||
else if (domainConfig.Response == null)
|
||||
{
|
||||
var scheme = context.Request.Scheme;
|
||||
var destinationPrefix = GetDestinationPrefix(scheme, host, domainConfig.Destination);
|
||||
|
||||
@ -2,6 +2,7 @@ using FastGithub.Configuration;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FastGithub
|
||||
{
|
||||
@ -46,6 +47,13 @@ namespace FastGithub
|
||||
app.UseRequestLogging();
|
||||
app.UseDnsOverHttps();
|
||||
app.UseReverseProxy();
|
||||
|
||||
app.UseRouting();
|
||||
app.UseEndpoints(endpoint => endpoint.MapFallback(context =>
|
||||
{
|
||||
context.Response.Redirect("https://github.com/dotnetcore/FastGithub");
|
||||
return Task.CompletedTask;
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user