This repository has been archived by the owner on Oct 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathProgram.cs
67 lines (61 loc) · 2.75 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.IO;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Hippo.Proxies;
using Hippo.Tasks;
[assembly: System.CLSCompliant(false)]
namespace Hippo
{
public static class Program
{
public static void Main(string[] args)
{
var hippoHostBuilder = CreateHostBuilder(args);
var hippoHost = hippoHostBuilder.Build();
var proxyUpdateTaskQueue = hippoHost.Services.GetRequiredService<ITaskQueue<ReverseProxyUpdateRequest>>();
var proxyHostBuilder = CreateProxyHostBuilder(proxyUpdateTaskQueue);
var proxyHost = proxyHostBuilder.Build();
var hippoTask = hippoHost.RunAsync();
var proxyTask = proxyHost.RunAsync();
Task.WaitAll(new Task[] { hippoTask, proxyTask });
}
// This has to be called CreateHostBuilder because the migrations tool looks specifically
// for that method name.
static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseConsoleLifetime()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.ConfigureServices(services =>
{
services.AddHostedService<ChannelUpdateBackgroundService>();
});
static IHostBuilder CreateProxyHostBuilder(ITaskQueue<ReverseProxyUpdateRequest> proxyUpdateTaskQueue) =>
Host.CreateDefaultBuilder()
.UseConsoleLifetime()
.UseContentRoot(Path.Combine(Directory.GetCurrentDirectory(), "Proxies"))
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<ProxyStartup>();
})
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.Sources.Clear();
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables("HIPPO_REVERSE_PROXY_");
})
.ConfigureServices(services =>
{
services.AddSingleton(proxyUpdateTaskQueue);
services.AddHostedService<ReverseProxyUpdateBackgroundService>();
});
}
}