-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathProgram.cs
52 lines (46 loc) · 1.58 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
using FUNC;
using Microsoft.Net.Http.Headers;
using Yarp.ReverseProxy.Transforms;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddWindowsService();
builder.Services.AddSystemd();
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(3536);
var cert = X509.Generate(subject: "FUNC");
options.ListenAnyIP(3537, listenOptions =>
{
listenOptions.UseHttps(cert);
});
options.ListenAnyIP(3538, listenOptions =>
{
listenOptions.UseHttps(cert);
});
});
builder.Services.AddReverseProxy()
.LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"))
.AddTransforms(transformBuilderContext =>
{
transformBuilderContext.AddRequestTransform(transformContext =>
{
var ogPort = transformContext.HttpContext.Request.Host.Port;
var destPort = ogPort == 3538 ? Shared.VoiPort : Shared.AlgoPort;
var newUri = new UriBuilder(transformContext.DestinationPrefix) { Port = destPort }.Uri;
transformContext.DestinationPrefix = newUri.ToString();
return ValueTask.CompletedTask;
});
});
var app = builder.Build();
// Configure the HTTP request pipeline.
app.Use(async (httpContext, next) =>
{
httpContext.Response.Headers[HeaderNames.CacheControl] = "no-cache, no-store, must-revalidate";
await next();
});
app.UseCors(options => options.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
app.MapControllers();
app.UseFileServer();
app.MapReverseProxy();
app.Run();