I would like to integrate Vue in my .net MVC project. I've installed Vue using the CLI and added the following vue.config.js:

module.exports = {
  devServer: {
    proxy: {
      '/': {
        target: 'http://mvcsite.local',
        changeOrigin: true
      }
    },
    disableHostCheck: true
  },
  runtimeCompiler: true
};

The proxy works fine, except that a request to the root http://localhost:8080 (which the dev server runs at) serves the index.html generated by Vue, rather than proxying the request to the root of http://mvcsite.local. How do I proxy that particular request?

1 Answers

1
Marco On Best Solutions

As indicated in your comment, there is an open issue on github for this, so currently there seems to be no fix. In my case (ASP.NET MVC 4) I solved the problem using a workaround. I simply move the root dir to /Home in development environment. Of course your server backend has to support this scenario, but that's usually the smaller problem. My working vue.config.js for @vue/cli 3 looks like this:

module.exports = {

publicPath: "/Home",

devServer: {
    publicPath: "/Home",
    proxy:
    {
        '^/Home/*': {
            target: 'http://localhost:50353/',
            ws: true,
            changeOrigin: true
        }

    },

}