Nuxt代理配置:如何创建使用阵列模式?

问题描述 投票:0回答:1

nuxt-config.js中,为什么代理在对象模式下起作用而不在数组模式下起作用?

Works:将/ api / v2 / inventory / 3906代理到nitro.noxgroup.co.za/v2/inventory/3906

proxy: {
    '/api': {
        target: 'https://nitro.noxgroup.co.za',
        pathRewrite: {
            '^/api': '/'
        }
    }
},

“阵列模式”不起作用:另外,尝试代理货币兑换服务

proxy: [
    {'/api': {
        target: 'https://nitro.noxgroup.co.za',
        pathRewrite: {
            '^/api': '/'
        }
    }},
    {'/api-currency': {
        target: 'https://rate-exchange-1.appspot.com',
        pathRewrite: {
            '^/api-currency': '/'
        }
    }},
]

错误:

FATAL  [HPM] Missing "target" option. Example: {target: "http://www.example.org"}      
javascript proxy nuxt.js
1个回答
0
投票

在阵列模式下,配置由阵列和字符串组成。如果您将路径与config一起使用,则其数组为:

[ path, { ...config } ] 

不是对象

{ [path]: { ... config } }

示例:

proxy: [
    ['/api', {
        target: 'https://nitro.noxgroup.co.za',
        pathRewrite: {
            '^/api': '/'
        }
    }],
    ['/api-currency', {
        target: 'https://rate-exchange-1.appspot.com',
        pathRewrite: {
            '^/api-currency': '/'
        }
    }],
]
© www.soinside.com 2019 - 2024. All rights reserved.