// 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) { app.UseStaticFiles(); // For any requests coming in from '/dist/**/*' or '__webpack_hmr', we wan't to proxy those requests // to our webpack dev server that is running. // Make sure you have 'gulp dev' running before starting the .NET web stuff. // NOTE: You may want to configure this to only run on a dev environment, and not production. var proxyOptions = new OptionsWrapper<ProxyOptions>(new ProxyOptions { Host = "localhost", Port = "5001" }); app.Use(async (context, next) => { if(!context.Request.Path.StartsWithSegments("/dist") && !context.Request.Path.StartsWithSegments("/__webpack_hmr")) { await next(); return; } var proxyMiddleware = new ProxyMiddleware(httpContext => next.Invoke(), proxyOptions); await proxyMiddleware.Invoke(context); }); app.UseJsEngine(); // this needs to be before MVC app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
public ApiProxyMiddleware(RequestDelegate next, IOptions <ApiProxyServerOptions> apiServerOptions, ILoggerFactory loggerFactory) { _apiUri = apiServerOptions.Value.ToUri().AbsoluteUri; _proxy = new ProxyMiddleware(next, apiServerOptions.Value.ToProxyOptions()); _logger = loggerFactory.CreateLogger <ApiProxyMiddleware>(); }
public ApiProxyMiddleware(RequestDelegate next, IOptions <ApiProxyServerOptions> apiServerOptions) { _proxy = new ProxyMiddleware(next, apiServerOptions.Value.ToProxyOptions()); }