【问题标题】:AWS Amplify 405 MethodNotAllowed error in POST method with Nuxt.js Proxy使用 Nuxt.js 代理的 POST 方法中的 AWS Amplify 405 MethodNotAllowed 错误
【发布时间】:2021-06-15 15:01:40
【问题描述】:

尝试将 API 与我使用 Nuxt.js 构建并使用 AWS Amplify 托管的应用程序集成。我添加了一个代理,它在本地运行良好,但它在 AWS 服务器中为 POST 方法返回 405 MethodNotAllowed

对于代理,我进行了如下更改以重写路径:

axios: {
 proxy: true
},
proxy: {
 '/lead/': { target: 'https://api.apidomain.org/v2', pathRewrite: { '^/lead/': '' }, 
  changeOrigin: true }
},

我已经阅读了 Amplify documentation,我们可以在其中更新重定向,所以我尝试过

[
{
    "source": "/<*>",
    "target": "/index.html",
    "status": "404-200",
    "condition": null
},
{
    "source": "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>",
    "target": "/index.html",
    "status": "200",
    "condition": null
},
{
    "source": "/lead/<*>",
    "target": "https://api.apidomain.org/v2/<*>",
    "status": "200",
    "condition": null
}
]

前两个规则是默认规则,我添加了第三个规则,但仍然收到 405 MethodNotAllowed 错误。我错过了什么?

【问题讨论】:

    标签: amazon-web-services vue.js proxy nuxt.js aws-amplify


    【解决方案1】:

    放大重定向从列表顶部向下执行。这已通过重新排序规则得到解决。

    [
    {
        "source": "/lead/<*>",
        "target": "https://api.apidomain.org/v2/<*>",
        "status": "200",
        "condition": null
    },
    {
        "source": "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|woff2|ttf|map|json)$)([^.]+$)/>",
        "target": "/index.html",
        "status": "200",
        "condition": null
    }
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-26
      • 1970-01-01
      • 2012-08-24
      • 2018-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-16
      相关资源
      最近更新 更多