aspnetcore-vueclimiddleware icon indicating copy to clipboard operation
aspnetcore-vueclimiddleware copied to clipboard

Route Pattern not working

Open Bleizingard opened this issue 5 years ago • 4 comments

Hi !

I'm using the version 3.1.1.

I define the MapToVueCliProxy route pattern as follow

endpoints.MapToVueCliProxy( "booking", new SpaOptions { SourcePath = "../Kronos.BookingClient" }, npmScript: System.Diagnostics.Debugger.IsAttached ? "serve" : null, regex: "Compiled successfully", forceKill: true, https: true);

My website continue to serve the vuejs project on root (https://localhost:44389/ instead of https://localhost:44389/booking)

I also tried

endpoints.MapToVueCliProxy( "booking/{*path}", new SpaOptions { SourcePath = "../Kronos.BookingClient" }, npmScript: System.Diagnostics.Debugger.IsAttached ? "serve" : null, regex: "Compiled successfully", forceKill: true, https: true);

I suppose it is not a normal behavior. Am I wrong ?

Bleizingard avatar Sep 05 '20 10:09 Bleizingard

i have the same issue

            app.UseEndpoints(endpoints =>
            {          
                endpoints.MapToVueCliProxy(
                    "admin/{*path}",
                    new SpaOptions {SourcePath = "client-app"},
                    npmScript: (System.Diagnostics.Debugger.IsAttached) ? "serve" : null,
                    regex: "Compiled succesfully",
                    forceKill: true);
                endpoints.MapDefaultControllerRoute();
            });

and my vue.config.js

module.exports = {
    publicPath: '/admin/',
}

ucanbaklava avatar Sep 16 '20 13:09 ucanbaklava

AFAIK the debugger will continue to server addresses at the ROOT even with things like app.UsePathBase and custom mappings added. Can you see if your app works at the custom URL as well as the root? I've experienced similar issues with aspnetcore routing.

EEParker avatar Jan 11 '21 15:01 EEParker

The route pattern seems to work here, combined with a vue.config.js file:

Startup.Configure:

...
app.UseSpaStaticFiles(new() { RequestPath = "/clientapp" });
...
app.UseEndpoints(endpoints =>
{
   ...
   endpoints.MapToVueCliProxy(
      "clientapp/{*path}",
      ...
   );
});

vue.config.js:

module.exports = {
	publicPath: '/clientapp/'
}

Unfortunately hot reload doesn't work after these changes. It seems that the browser cannot connect to the hot reload socket as it continuously reciecves 404 for requests to https://localhost:44366/sockjs-node/info?t=1625221399928 (with changing numbers).

Could this be due to the sockjs-node/ route being filtered out by the endpoint pattern? Would there be a way to work around this?

teisnet avatar Jul 02 '21 10:07 teisnet

The solution to the hot reload not working is to configure Webpack's devserver to serve the socket from the same subroute as the Vue app itself, like so:

vue.config.js:

module.exports = {
	publicPath: '/clientapp/',
	devServer: {
		public: 'localhost',
		sockPath: '/clientapp/sockjs-node'
	}
}

(for some reason the public: '<ip-address>' field is required for the new sockPath to take effect, as mentioned here)

teisnet avatar Jul 03 '21 08:07 teisnet