zoukankan      html  css  js  c++  java
  • webpack-dev-server 本地代理proxy

    proxy: [
        {
            context: ['/user', '/rights', '/resource/getAdNotice'],
            target: 'https://plus.m.jd.com',
            secure: false,
            changeOrigin: true,
            headers: {
                cookie: domCookies
            }
        },
        {
            context: ['/apis'],
            target: 'https://rsp.jd.com/',
            secure: false,
            changeOrigin: true,
            pathRewrite: {'^/apis': ''},
            headers: {
                cookie: domCookies,
                referer: 'https://plus.m.jd.com'
            }
        }
    ]

     post请求:

    proxy:{
                    '/user':{
                        target: 'https://plus.m.jd.com',
                        secure: false,
                        changeOrigin: true,
                        headers: {
                            cookie: domCookies
                        }
                    },
                    '/rights':{
                        target: 'https://plus.m.jd.com',
                        secure: false,
                        changeOrigin: true,
                    },
                    '/resource/getAdNotice':{
                        target: 'https://plus.m.jd.com',
                        secure: false,
                        changeOrigin: true,
                    },
                    '/apis':{
                        target: 'https://rsp.jd.com/',
                        secure: false,
                        ws: true,
                        changeOrigin: true,
                        pathRewrite: {'^/apis': ''},
                        headers: {
                            referer: 'https://plus.m.jd.com'
                        }
                    },
                    '/apipost': {
                        target: 'https://rsp.jd.com/',
                        secure: false,
                        changeOrigin: true,
                        ws: true,
                        pathRewrite: {'^/apipost': ''},
                        headers: {
                            origin: 'https://plus.m.jd.com',
                            host: 'rsp.jd.com',
                            referer: 'https://plus.m.jd.com/index'
                        }
                    }
                }

     化简为:

                proxy: [
                    {
                        context: ['/user', '/rights', '/resource/getAdNotice'],
                        target: 'https://plus.m.jd.com',
                        secure: false,
                        changeOrigin: true,
                    },
                    {
                        context: ['/apis'],
                        target: 'https://rsp.jd.com/',
                        secure: false,
                        ws: true,
                        changeOrigin: true,
                        pathRewrite: {'^/apis': ''},
                        headers: {
                            origin: 'https://plus.m.jd.com',
                            host: 'rsp.jd.com',
                            referer: 'https://plus.m.jd.com/index'
                        }
                    }  
                ]

    核心思想,正式中的header中有啥,代理中写上啥。

    设置环境变量

    new webpack.DefinePlugin({
    'process.env.NODE_ENV': JSON.stringify('care')
    }),
  • 相关阅读:
    线性dp打鼹鼠
    区间dp(能量项链)
    留言板
    友链
    CodeForces 1270I Xor on Figures
    agc020_d Min Max Repetition
    Codeforces 1270G Subset with Zero Sum
    CodeForecs 1270E Divide Points
    MybatisPlus学习笔记10:公共字段自动填充
    MybatisPlus学习笔记9:自定义全局操作
  • 原文地址:https://www.cnblogs.com/xiaozhumaopao/p/11853210.html
Copyright © 2011-2022 走看看