A. Tretiakov
A. Tretiakov

Reputation: 161

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.

Upvotes: 5

Views: 9296

Answers (1)

A. Tretiakov
A. Tretiakov

Reputation: 161

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.

Upvotes: 8

Related Questions