-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startup.cs
71 lines (62 loc) · 2.38 KB
/
Startup.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
68
69
70
71
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.IISIntegration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace iisbridge
{
public class Startup
{
private ExecutableHandler exeHandler;
private IConfiguration config;
public Startup(IConfiguration config) {
this.config = config;
}
public void ConfigureServices(IServiceCollection services)
{
// Configure Authentication
services.AddAuthentication(IISDefaults.AuthenticationScheme);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime applicationLifetime)
{
// Register Shutdown Event
applicationLifetime.ApplicationStopping.Register(OnShutdown);
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
// Configure & Start web app process handler
exeHandler = new ExecutableHandler(
config.GetValue<string>("appSettings:appProcessName"),
config.GetValue<string>("appSettings:appProcessArgs"),
config.GetValue<int>("appSettings:appProcessPort"),
ParseEnvConfig(config.GetValue<string>("appSettings:appProcessEnv")));
exeHandler.Start();
// Configure reverse proxy
app.UseReverseProxy(new ReverseProxyOptions {
BaseUrl = $"http://localhost:" + config.GetValue<int>("appSettings:appProcessPort"),
ExecutableHandler = exeHandler
});
}
public void OnShutdown() {
exeHandler.Stop();
}
private Dictionary<string, string> ParseEnvConfig(string config)
{
if (config != null) {
string[] envSettings = config.Split(';');
Dictionary<string, string> dict = envSettings
.ToDictionary(setting => setting.Split("=")[0], setting => setting.Split("=")[1]);
return dict;
}
return new Dictionary<string, string>();
}
}
}