JavaScript/vue.js/proxy:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
 
第33行: 第33行:
| 示例 || 示例 || 示例
| 示例 || 示例 || 示例
|}
|}
== 示例 ==
<syntaxhighlight lang="javascript">
/**
* 在生产环境 代理是无法生效的,所以这里没有生产环境的配置
*/
module.exports = {
    development: {
        target:{
            '/api': {
                target: 'http://localhost:3000',
                // 多个特定路径代理到同一目标
                // context: ['/docs', '/api'],
                // 支持https
                secure: false,
                // logLevel: 'debug' 将代理转发过程,打印在命令行中,方便调试
                logLevel: 'debug',
                // 接口跨域
                // 后端收到的请求头中的host是目标地址 target
                // 设置为 true, 本地就会虚拟一个服务器接收你的请求并代你发送该请求
                changeOrigin: true,
                pathRewrite: {'^/api' : ''},
                ifProxy: false,
                // header: {
                //    'Origin': '',
                //    'referer': ''
                // }
            },
            // '/docs': {
            //    targetHost: 'DOCSHOST',
            //    target: 'http://localhost:3000',
            //    secure: false,
            //    changeOrigin: false,
            //    pathRewrite: { '^/LOCAL': '' },
            //    ifProxy: false,
            // },
        },
        staticHost: `/staticHost/`,
        cloudStaticHost: `cloudStaticHost`,
    },
    production: {
        target:{
        }
    },
}
  </syntaxhighlight>
== 参考 ==
== 参考 ==
* https://webpack.docschina.org/configuration/dev-server/#devserverproxy
* https://webpack.docschina.org/configuration/dev-server/#devserverproxy