Skip to content

Commit c961b0e

Browse files
author
wangnima
committed
administraton 几乎完成
1 parent 38dfd6f commit c961b0e

File tree

5 files changed

+35
-36
lines changed

5 files changed

+35
-36
lines changed

Hei.OcelotOnK8s/Hei.OcelotOnK8s/Hei.OcelotOnK8s.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<ItemGroup>
88
<PackageReference Include="Ocelot" Version="16.0.1" />
9+
<PackageReference Include="Ocelot.Administration" Version="16.0.1" />
910
</ItemGroup>
1011

1112
<ProjectExtensions><VisualStudio><UserProperties ocelot_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>

Hei.OcelotOnK8s/Hei.OcelotOnK8s/Program.cs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,6 @@ namespace Hei.OcelotOnK8s
1414
{
1515
public class Program
1616
{
17-
public static void Main2(string[] args)
18-
{
19-
new WebHostBuilder()
20-
.UseKestrel()
21-
.UseContentRoot(Directory.GetCurrentDirectory())
22-
.ConfigureAppConfiguration((hostingContext, config) =>
23-
{
24-
config
25-
.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
26-
.AddJsonFile("appsettings.json", true, true)
27-
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
28-
.AddJsonFile("ocelot.json")
29-
.AddEnvironmentVariables();
30-
})
31-
.ConfigureServices(s =>
32-
{
33-
s.AddOcelot();
34-
})
35-
.ConfigureLogging((hostingContext, logging) =>
36-
{
37-
//add your logging
38-
})
39-
//.UseIISIntegration()
40-
.Configure(app =>
41-
{
42-
app.UseOcelot().Wait();
43-
})
44-
.Build()
45-
.Run();
46-
}
47-
4817
public static void Main(string[] args)
4918
{
5019
CreateHostBuilder(args).Build().Run();

Hei.OcelotOnK8s/Hei.OcelotOnK8s/Startup.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Threading.Tasks;
5+
using IdentityServer4.AccessTokenValidation;
56
using Microsoft.AspNetCore.Builder;
67
using Microsoft.AspNetCore.Hosting;
78
using Microsoft.AspNetCore.Http;
89
using Microsoft.Extensions.Configuration;
910
using Microsoft.Extensions.DependencyInjection;
1011
using Microsoft.Extensions.Hosting;
12+
using Ocelot.Administration;
1113
using Ocelot.DependencyInjection;
1214
using Ocelot.Middleware;
1315

@@ -23,21 +25,28 @@ public Startup(IConfiguration configuration, IWebHostEnvironment env)
2325
.SetBasePath(env.ContentRootPath)
2426
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
2527
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)
26-
.AddJsonFile("ocelot.json");
28+
.AddJsonFile("ocelot.json")
29+
.AddJsonFile($"ocelot.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
2730
Configuration = builder.Build();
2831
}
2932

3033
// This method gets called by the runtime. Use this method to add services to the container.
3134
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
3235
public void ConfigureServices(IServiceCollection services)
3336
{
34-
services.AddOcelot(Configuration);
37+
services.AddOcelot(Configuration).AddAdministration("/administration", options=>
38+
{
39+
options.Authority = "http://passport-test.39.net";///connect/token
40+
options.ApiName = "api1";
41+
options.RequireHttpsMetadata = false;
42+
options.SupportedTokens = SupportedTokens.Both;
43+
options.ApiSecret = "secret";
44+
});
3545
}
3646

3747
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
3848
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
3949
{
40-
app.UseRouting();
4150
app.UseOcelot().Wait();
4251
}
4352
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"Routes": [
3+
{
4+
"UpstreamPathTemplate": "/api/{url}",
5+
"DownstreamPathTemplate": "/{url}",
6+
"DownstreamScheme": "http",
7+
"DownstreamHostAndPorts": [
8+
{
9+
"Host": "localhost",
10+
"Port": 5003
11+
}
12+
],
13+
14+
"UpstreamHttpMethod": [ "Get" ]
15+
}
16+
],
17+
"GlobalConfiguration": {
18+
"BaseUrl": "http://localhost:5000"
19+
}
20+
}

Hei.OcelotOnK8s/Hei.OcelotOnK8s/ocelot.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"Routes": [
33
{
4-
"UpstreamPathTemplate": "/{id}",
5-
"DownstreamPathTemplate": "/{id}",
4+
"UpstreamPathTemplate": "/{url}",
5+
"DownstreamPathTemplate": "/{url}",
66
"DownstreamScheme": "http",
77
"DownstreamHostAndPorts": [
88
{

0 commit comments

Comments
 (0)