• vuecli 中的devServer配置代理


    场景一:

    devServer: {
        proxy: {
            '/api': 'http://localhost:3000'
        }
    }
    请求到 /api/xxx 现在会被代理到请求 http://localhost:3000/api/xxx,
    例如 /api/user 现在会被代理到请求 http://localhost:3000/api/user


    场景二:
    多个路径代理到同一个target下, 你可以使用由一个或多个「具有 context 属性的对象」构成的数组:
    复制代码
    devServer: {
        proxy: [{
            context: ['/auth', '/api'],
            target: 'http://localhost:3000',
        }]
    }
    复制代码

    场景三:

    不始终传递 /api ,则需要重写路径:

    复制代码
    devServer: {
        proxy: {
            '/api': {
                target: 'http://localhost:3000',
                pathRewrite: {'^/api' : ''}
            }
        }
    }
    复制代码

    请求到 /api/xxx 现在会被代理到请求 http://localhost:3000/xxx,

    例如 /api/detail 现在会被代理到请求 http://localhost:3000/detail

    场景四:

    默认情况下,不接受运行在 HTTPS 上,且使用了无效证书的后端服务器。

    如果你想要接受,只要设置 secure: false 就行。修改配置如下:

    复制代码
    devServer: {
        proxy: {
            '/api': {
                target: 'https://other-server.example.com',
                secure: false,
                changeOrigin: true
            }
        }
    }
    复制代码

    changeOrigin 是一个布尔值, 设置为true, 本地就会虚拟一个服务器接收你的请求并代你发送该请求。

  • 相关阅读:
    20171104 DOI Excel 导出
    ABAP 字符串处理
    SE80 开发对象
    ABAP开发中message dump
    物料单位转换的两个函数
    ABAP 多行消息分别显示弹窗
    隐藏你写的程序代码
    学习笔记:Javascript 变量 包装对象
    访问平安银行网站时出现证书问题 NET::ERR_CERT_SYMANTEC_LEGACY
    关于跨域问题
  • 原文地址:https://www.cnblogs.com/zjianfei/p/14754118.html
Copyright © 2020-2023  润新知