Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use UseProxyToSpaDevelopmentServer from inside of local service fabric cluster?

I was trying to use UseProxyToSpaDevelopmentServer option from inside of local service fabric cluster and I got no results. I literally didn't get any requests from server, when I was trying to access SPA application by route http://localhost:9000/UI/. I'm using asp.net core 2.1 angular template. I use Razor to create an initial Angular page.

My Startup class looks like:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
        }

        app.UseStaticFiles();
        app.UseSpaStaticFiles();

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

        app.UseSpa(spa =>
        {
            // To learn more about options for serving an Angular SPA from ASP.NET Core,
            // see https://go.microsoft.com/fwlink/?linkid=864501
            spa.Options.SourcePath = "ClientApp";

            if (env.IsDevelopment())
            {
                spa.UseProxyToSpaDevelopmentServer("http://localhost:4200/");
            }
        });
    }

I'm running application in development mode for sure. I tried to get any request by launching basic node js server as well as angular app with ng serve command, but as I said got no results.

like image 966
A. Tretiakov Avatar asked Nov 19 '18 20:11

A. Tretiakov


1 Answers

I actually figured it out. The problem is app.UseSpa is coming after app.UseMvc. Since my razor page has been called Index.cshtml, MVC is taking over Spa requests.

like image 186
A. Tretiakov Avatar answered Oct 11 '22 10:10

A. Tretiakov