node.js - webpack-dev-server 如何解决跨域请求!!
天蓬老师
天蓬老师 2017-04-17 13:40:27
[Node.js讨论组]

1.loaclhost:8080 webpack-dev-server 本地服务器,接口请求地址是api.xxx.com,现在就是无法在本地请求远程服务器上的接口。

XMLHttpRequest cannot load http://api.xxx.com/v1/f/shares.
 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 403.

有找过相关资料。配置不造是错了还是什么不起作用。

    entry:[
        'webpack/hot/only-dev-server',
        './src/main.js'
    ],
    devServer: {
        hot: true,
        inline: true,
        proxy: {
            '*': {
                target: 'localhost:8080',
                host:'http://m.xxx.com',
                secure: false,
            }
        }
    },
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回复(1)
天蓬老师
changeOrigin: true
target: http://api.xxx.com

然后改成你本地引用的地址,比如/api/
其他地方调用的时候,就写ajax('/api/xxx')之类的

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号