gpt4 book ai didi

javascript - 代理从 webpack 开发服务器到 .net MVC 站点的请求

转载 作者:行者123 更新时间:2023-11-30 19:43:38 24 4
gpt4 key购买 nike

我想将 Vue 集成到我的 .net MVC 项目中。我已经使用 CLI 安装了 Vue并添加了以下 vue.config.js:

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

代理工作正常,除了对根 http://localhost:8080(开发服务器运行的地方)的请求服务于 Vue 生成的 index.html,而不是代理向 http://mvcsite.local 的根请求。我如何代理该特定请求?

最佳答案

如您的评论所述,github 上有一个 Unresolved 问题,因此目前似乎没有修复。就我而言(ASP.NET MVC 4),我使用变通方法解决了问题。我只是将根目录移动到开发环境中的/Home。当然,您的服务器后端必须支持这种情况,但这通常是较小的问题。我为@vue/cli 3 工作的 vue.config.js 看起来像这样:

module.exports = {

publicPath: "/Home",

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

},

}

关于javascript - 代理从 webpack 开发服务器到 .net MVC 站点的请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55149668/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com