-
Notifications
You must be signed in to change notification settings - Fork 905
Expand file tree
/
Copy pathProgram.cs
More file actions
41 lines (33 loc) · 1.18 KB
/
Program.cs
File metadata and controls
41 lines (33 loc) · 1.18 KB
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Yarp.ReverseProxy.Configuration;
// Load configuration
if (args.Length != 1)
{
Console.Error.WriteLine("Usage: yarp.exe <config_file>");
return 1;
}
var configFile = args[0];
var fileInfo = new FileInfo(configFile);
if (!fileInfo.Exists)
{
Console.Error.WriteLine($"Could not find '{configFile}'.");
return 2;
}
var builder = WebApplication.CreateBuilder();
builder.Configuration.AddJsonFile(fileInfo.FullName, optional: false, reloadOnChange: true);
// Configure YARP
builder.AddServiceDefaults();
builder.Services.AddServiceDiscovery()
.AddOutputCache(builder.Configuration.GetSection("OutputCache"));
builder.Services.AddReverseProxy()
.LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"))
.AddServiceDiscoveryDestinationResolver();
var app = builder.Build();
app.MapReverseProxy();
await app.RunAsync();
return 0;