zoukankan      html  css  js  c++  java
  • 使用ocelot作为api网关

    • 新建网站项目然后添加ocelot 的nuget包
    • 新建ocelot.json的网关的配置文件
      {
        "GlobalConfiguration": {
          "BaseUrl": "https://api.mybusiness.com"
        },
        "ReRoutes": [
          {
            "DownstreamPathTemplate": "/api/values",
            "DownstreamScheme": "http",
            "DownstreamHostAndPorts": [
              {
                "Host": "localhost",
                "Port": 60907
              }
            ],
            "UpstreamPathTemplate": "/users",
            "UpstreamHttpMethod": [ "Get" ],
            "AuthenticationOptions": {
              "AuthenticationProviderKey": "finbook",
              "AllowedScopes": []
            }
          },
          {
            "DownstreamPathTemplate": "/connect/token",
            "DownstreamScheme": "http",
            "DownstreamHostAndPorts": [
              {
                "Host": "localhost",
                "Port": 52619
              }
            ],
            "UpstreamPathTemplate": "/connect/token",
            "UpstreamHttpMethod": [ "Post" ]
          }
        ]
      }
    • 添加配置文件进入netcore管道
          public class Program
          {
              public static void Main(string[] args)
              {
                  BuildWebHost(args).Run();
              }
      
              public static IWebHost BuildWebHost(string[] args) =>
                  WebHost.CreateDefaultBuilder(args)
                       .ConfigureAppConfiguration((hostingContext, builder) =>
                       {
                           builder
                           .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
                           .AddJsonFile("Ocelot.json");
                       })
                      .UseStartup<Startup>()
                      .Build();
          }
             public void ConfigureServices(IServiceCollection services)
              {
                  services.AddOcelot();
              }
    • 集成identityserver
        services.AddAuthentication()
         .AddIdentityServerAuthentication(authenticationProviderKey, options=> {
                          options.Authority = "http://localhost:52619/";
                          options.ApiName = "geteway_api";
                          options.SupportedTokens = SupportedTokens.Both;
                          options.ApiSecret = "secret";
                          options.RequireHttpsMetadata = false;//是否是https请求
                      });
    • 参考自大佬文章http://www.jessetalk.cn/2018/03/19/net-core-apigateway-ocelot-docs/
  • 相关阅读:
    SCRUM团队
    SCRUM的四大支柱
    SCRUM的五个价值观
    SCRUM的五个事件
    SCRUM的三个工件
    SCRUM团队的三个角色
    经验性过程
    Windows UWP开发系列 – RelativePanel
    Windows UWP开发系列 – 控件默认样式
    Windows UWP开发系列 – 3D变换
  • 原文地址:https://www.cnblogs.com/chongyao/p/10436927.html
Copyright © 2011-2022 走看看