VUE 3 CLI 项目正在为 sockjs-node 刷新调用阻止 CORS(在 API 调用的配置中使用代理)
VUE 3 CLI Project is blocking CORS for the sockjs-node refresh call (Using a Proxy in config for API Calls)
我正在 运行在本地主机上创建一个 VUE 3 CLI 项目
我需要调用一个远程服务器来获取数据。浏览器阻止了这个 CORS,所以我必须学习如何在 vue 配置中设置正确的 api headers 和代理。
我的 vue.config.js 文件包含以下内容:
devServer: {
https: true,
proxy: {
'^/api': {
target: 'https://api.mysite.com/',
ws: true,
changeOrigin: true
}
}
},
这解决了我从本地主机到远程服务器的 CORS 块,但导致了标题中的问题。它现在认为对 sockjs-node 文件的调用是跨源的。
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://192.168.29.243:8080/sockjs-node/info?t=1615826901010. (Reason: CORS request did not succeed).
我似乎找不到任何原因或解决方案。有没有人 运行 参与其中并知道该怎么做?
这对我来说已经解决了。
请检查以下 link:
// vue.config.js
module.exports = {
devServer: {
proxy: {
"^/api": {
target: "https://localhost:44345",
ws: true,
changeOrigin: true,
},
},
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept",
},
public: "http://localhost:44345",
disableHostCheck: true,
},
};
我正在 运行在本地主机上创建一个 VUE 3 CLI 项目
我需要调用一个远程服务器来获取数据。浏览器阻止了这个 CORS,所以我必须学习如何在 vue 配置中设置正确的 api headers 和代理。
我的 vue.config.js 文件包含以下内容:
devServer: {
https: true,
proxy: {
'^/api': {
target: 'https://api.mysite.com/',
ws: true,
changeOrigin: true
}
}
},
这解决了我从本地主机到远程服务器的 CORS 块,但导致了标题中的问题。它现在认为对 sockjs-node 文件的调用是跨源的。
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://192.168.29.243:8080/sockjs-node/info?t=1615826901010. (Reason: CORS request did not succeed).
我似乎找不到任何原因或解决方案。有没有人 运行 参与其中并知道该怎么做?
这对我来说已经解决了。
请检查以下 link:
// vue.config.js
module.exports = {
devServer: {
proxy: {
"^/api": {
target: "https://localhost:44345",
ws: true,
changeOrigin: true,
},
},
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept",
},
public: "http://localhost:44345",
disableHostCheck: true,
},
};