以下代码在 chrome 和 firefox 本地运行良好,无需安装 cors 插件。但是,当我创建构建并将静态文件放置到位于 /var/www/html 的生产服务器 droplet 时,它不起作用。请让我知道如何更改此配置文件以进行生产,我也没有收到 cors 错误。就像在本地没有得到 cors 或任何错误一样。
这是我的 vue.config.js 文件:
module.exports = {
devserver: {
proxy: {
"/one": {
target: "https://etherscan.io/",pathRewrite: { "^/one": "" },},"/two": {
target: "https://bscscan.com/",pathRewrite: { "^/two": "" },};
此外,这是请求:
this.$http
.get("http://localhost:8080/one/token/" + this.contractAddress,{
mode: "no-cors",header: {
"access-control-allow-origin": "http://localhost:8080/",gzip: true,})
同一组件中的第二个请求是:
this.$http
.get("http://localhost:8080/two/token/" + this.contractAddress,{
mode: "no-cors",header: {
"access-control-allow-origin": "http://localhost:8080/",})
部署后出错,当我通过 IP 地址打开部署的应用程序时:
然后我尝试将 URL 中的 http://localhost:8080 替换为 http//:localhost 并且在访问控制允许源中我放置了 http://ip 或 server/ 然后错误