-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Program.cs
78 lines (74 loc) · 2.84 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
68
69
70
71
72
73
74
75
76
77
78
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
using Ocelot.Requester;
using System.IO;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace Ocelot.ManualTest
{
public class Program
{
public static void Main(string[] args)
{
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.ConfigureAppConfiguration((hostingContext, config) =>
{
config
.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
.AddJsonFile("appsettings.json", true, true)
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
.AddJsonFile("ocelot.json", false, false)
.AddEnvironmentVariables();
})
.ConfigureServices(s =>
{
s.AddAuthentication();
/*.AddJwtBearer("TestKey", x =>
{
x.Authority = "test";
x.Audience = "test";
});*/
s.AddSingleton<QosDelegatingHandlerDelegate>((x, t, z) => new FakeHandler());
s.AddOcelot()
.AddDelegatingHandler<FakeHandler>(true);
/*.AddCacheManager(x =>
{
x.WithDictionaryHandle();
})
.AddOpenTracing(option =>
{
option.CollectorUrl = "http://localhost:9618";
option.Service = "Ocelot.ManualTest";
})
.AddAdministration("/administration", "secret");*/
})
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
logging.AddConsole();
})
.UseIISIntegration()
.Configure(app =>
{
app.UseOcelot(options =>
{
options.PreAuthenticationMiddleware = CustomOcelotMiddleware.Invoke;
}).Wait();
})
.Build()
.Run();
}
}
public class FakeHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
Console.WriteLine(request.RequestUri);
//do stuff and optionally call the base handler..
return await base.SendAsync(request, cancellationToken);
}
}
}