Exemple #1
0
        // 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)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));

            app.UseSession();

            app.UseStaticFiles();

            app.UseAuthentication();

            app.UseCors("AllowLocalhostOrigin");

            app.Use(async(context, next) =>
            {
                int?port = context.Request.Host.Port;
                if (port.HasValue && port.Value == 8080 && !context.Request.Path.Value.StartsWith("/api"))
                {
                    ProxyHandler handler = new ProxyHandler(context);
                    handler.ProxyToApi();
                    handler.WriteResponse(context.Response);
                }
                else
                {
                    //continues through the rest of the pipeline
                    await next();
                }
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}"
                    );
            });
        }