WebSocket is closed before the connection is established when i'm using SPA package

Viewed 3382

I'm trying to make a web app using .net core(server-side) and angular(client-side). If i'm using Spa Package(installed using nuget), i'm getting the following warning:

WebSocket connection to 'ws://localhost:5000/sockjs-node/034/ye1v1gz5/websocket' failed: WebSocket is closed before the connection is established.

My web server is located at /localhost:5000. When i'm doing a REST request i'm getting page not found:

POST http://localhost:5000/api/login 404 (Not Found)

My server-side configuration is:

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
            app.UseHsts();
        }
        app.UseSpa(spa =>
        {
            spa.Options.SourcePath = "StorigiAng";
            if (env.IsDevelopment())
            {
                spa.UseAngularCliServer(npmScript: "start");
            }
        });
        app.UseStaticFiles();
        app.UseCookiePolicy();
        app.UseSession();
        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller}/{action}/{id?}"
            );
            routes.MapSpaFallbackRoute(
                name: "spa-fallback",
                defaults: new { Controller = "Home", Action = "Index"}
                );
        });

    }

Request done from angular:

this.http.post<User>('http://localhost:5000/api/login',JSON.stringify(user), this.httpOptions)
   .pipe(map(user => { return user; }));

In case i'm not using SPA, everything works well. But if i'm modifying something i have to rebuild all the app. I don't want that, I would like that if i'm modifying something to see the result immediately. How can i do that?

0 Answers
Related