You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase托管重写导致POST请求被识别为GET的问题

解决Firebase托管重写后POST请求被识别为GET的问题

问题分析

直接访问函数URL和本地模拟器时POST请求正常,但通过Firebase Hosting重写规则访问时被当作GET,说明问题出在托管到函数的请求转发环节,大概率是重写规则未明确允许POST方法导致的。

解决方案

  1. 修改firebase.json的重写规则
    在rewrite配置中添加method字段,明确指定允许的HTTP方法(包含POST):
{
    "hosting": {
        "public": "public",
        "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
        "rewrites": [
            {
                "source": "**",
                "function": "myFunc",
                "method": ["GET", "POST"]
            }
        ]
    },
    "functions": [
        {
            "source": "functions",
            "codebase": "default",
            "ignore": ["node_modules", ".git", "firebase-debug.log", "firebase-debug.*.log", "*.local"]
        }
    ]
}
  1. 重新部署配置
    执行以下命令重新部署Firebase托管和函数,确保新配置生效:
firebase deploy --only hosting,functions
  1. 额外排查点
  • 检查函数代码中是否有针对请求方法的错误判断,确认req.method的获取逻辑正确;
  • 若自定义域名有CDN或反向代理配置,确保其未修改请求方法;
  • 清除客户端缓存后重新测试POST请求。

内容的提问来源于stack exchange,提问作者JRJurman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 17:47:15