FastGithub/FastGithub/Program.cs
2021-07-13 18:00:28 +08:00

61 lines
2.0 KiB
C#

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using System.IO;
namespace FastGithub
{
class Program
{
/// <summary>
/// 程序入口
/// </summary>
/// <param name="args"></param>
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().RunWithWindowsServiceControl();
}
/// <summary>
/// 创建host
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public static IHostBuilder CreateHostBuilder(string[] args)
{
return Host
.CreateDefaultBuilder(args)
.UseWindowsService()
.UseBinaryPathContentRoot()
.ConfigureAppConfiguration(c =>
{
foreach (var jsonFile in Directory.GetFiles(".", "appsettings.*.json"))
{
c.AddJsonFile(jsonFile, optional: true);
}
})
.ConfigureServices((ctx, services) =>
{
services.AddAppUpgrade();
services.AddGithubDns(ctx.Configuration);
services.AddGithubReverseProxy();
services.AddGithubScanner(ctx.Configuration);
})
.ConfigureWebHostDefaults(web =>
{
web.Configure(app =>
{
app.UseGithubReverseProxy();
});
web.UseKestrel(kestrel =>
{
const string caPublicCerPath = "FastGithub_CA.cer";
const string caPrivateKeyPath = "FastGithub_CA.key";
kestrel.ListenLocalhost(443, listen => listen.UseGithubHttps(caPublicCerPath, caPrivateKeyPath));
});
});
}
}
}