diff --git a/FastGithub.Configuration/FastGithubConfig.cs b/FastGithub.Configuration/FastGithubConfig.cs index 7abcbe9..a8a52f0 100644 --- a/FastGithub.Configuration/FastGithubConfig.cs +++ b/FastGithub.Configuration/FastGithubConfig.cs @@ -28,7 +28,7 @@ namespace FastGithub.Configuration { this.logger = logger; var opt = options.CurrentValue; - + this.domainConfigs = ConvertDomainConfigs(opt.DomainConfigs); this.domainConfigCache = new ConcurrentDictionary(); @@ -42,7 +42,7 @@ namespace FastGithub.Configuration private void Update(FastGithubOptions options) { try - { + { this.domainConfigs = ConvertDomainConfigs(options.DomainConfigs); this.domainConfigCache = new ConcurrentDictionary(); } @@ -74,7 +74,7 @@ namespace FastGithub.Configuration /// public bool IsMatch(string domain) { - return this.domainConfigs.Keys.Any(item => item.IsMatch(domain)); + return this.TryGetDomainConfig(domain, out _); } /// diff --git a/FastGithub.HttpServer/HttpProxyMiddleware.cs b/FastGithub.HttpServer/HttpProxyMiddleware.cs index 0b5980c..aaffef1 100644 --- a/FastGithub.HttpServer/HttpProxyMiddleware.cs +++ b/FastGithub.HttpServer/HttpProxyMiddleware.cs @@ -105,7 +105,7 @@ namespace FastGithub.HttpServer return new IPEndPoint(address, targetPort); } - if (this.fastGithubConfig.TryGetDomainConfig(targetHost, out _) == false) + if (this.fastGithubConfig.IsMatch(targetHost) == false) { return new DnsEndPoint(targetHost, targetPort); } diff --git a/FastGithub/AppHostedService.cs b/FastGithub/AppHostedService.cs index eb5e8ea..31a46e4 100644 --- a/FastGithub/AppHostedService.cs +++ b/FastGithub/AppHostedService.cs @@ -23,7 +23,7 @@ namespace FastGithub public Task StopAsync(CancellationToken cancellationToken) { - this.logger.LogInformation($"{nameof(FastGithub)}止停止运行"); + this.logger.LogInformation($"{nameof(FastGithub)}已停止运行"); return Task.CompletedTask; } } diff --git a/FastGithub/Startup.cs b/FastGithub/Startup.cs index 008b0f4..c5a4b1b 100644 --- a/FastGithub/Startup.cs +++ b/FastGithub/Startup.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using System; +using System.Threading.Tasks; namespace FastGithub { @@ -59,6 +60,13 @@ namespace FastGithub { appBuilder.UseRequestLogging(); appBuilder.UseHttpReverseProxy(); + + appBuilder.UseRouting(); + appBuilder.UseEndpoints(endpoint => endpoint.MapFallback(context => + { + context.Response.Redirect("https://github.com/dotnetcore/FastGithub"); + return Task.CompletedTask; + })); }); } }