Exemple #1
0
        public ApiProxyMiddleware(RequestDelegate next, IOptions <ApiProxyOptions> options)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            this.next    = next;
            this.options = options.Value;

            if (this.options.ProxiedEndpoints?.Count() <= 0)
            {
                throw new ArgumentException("Options do not contain any proxied endpoints", nameof(options));
            }
            foreach (var ep in this.options.ProxiedEndpoints)
            {
                if (!ep.Endpoint.StartsWith("/"))
                {
                    throw new Exception("Endpoint path must start with a slash '/'");
                }
            }

            this.client = new HttpClient();
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            var options = new ApiProxyOptions();
            options.ProxiedEndpoints = new[] { new ApiEndpointOption() { Endpoint = "/api2", Host = "localhost", TargetEndpoint = "/api" } };
            app.RunApiProxy(options);
            app.UseMvc();
        }
 public static IApplicationBuilder RunApiProxy(this IApplicationBuilder app, ApiProxyOptions options)
 {
     if (app == null)
     {
         throw new ArgumentNullException(nameof(app));
     }
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     return(app.UseMiddleware <ApiProxyMiddleware>(Options.Create(options)));
 }
        public ApiProxyMiddleware(RequestDelegate next, IOptions<ApiProxyOptions> options)
        {
            if (next == null) throw new ArgumentNullException(nameof(next));
            if (options == null) throw new ArgumentNullException(nameof(options));

            this.next = next;
            this.options = options.Value;

            if (this.options.ProxiedEndpoints?.Count() <= 0) throw new ArgumentException("Options do not contain any proxied endpoints", nameof(options));
            foreach (var ep in this.options.ProxiedEndpoints)
            {
                if (!ep.Endpoint.StartsWith("/")) throw new Exception("Endpoint path must start with a slash '/'");
            }

            this.client = new HttpClient();
        }
 public static IApplicationBuilder RunApiProxy(this IApplicationBuilder app, ApiProxyOptions options)
 {
     if (app == null) throw new ArgumentNullException(nameof(app));
     if (options == null) throw new ArgumentNullException(nameof(options));
     return app.UseMiddleware<ApiProxyMiddleware>(Options.Create(options));
 }