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

如何在GCP API Gateway实现类似AWS的Mock响应?部署后报503错误

GCP API Gateway Mock健康端点配置修复

你的问题出在没有配置GCP API Gateway所需的Mock后端集成——和AWS不同,GCP需要显式声明Mock类型的后端,否则网关会默认寻找真实上游服务,找不到就返回503错误。

需要在Swagger配置里补充以下关键内容:

  • 在get方法节点下添加x-google-backend字段,指定后端类型为MOCK
  • 可选:在200响应中明确返回内容(即使是空响应体也可以显式定义)

修复后的完整配置示例(带简单响应体):

swagger: "2.0"
info:
  version: 1.0.0
  title: some API
paths:
  /health:
    get:
      operationId: healthCheck
      summary: Health check endpoint
      x-google-backend:
        type: MOCK
      responses:
        '200':
          description: Successful health check
          schema:
            type: object
            properties:
              status:
                type: string
                example: "healthy"

如果只需要纯200状态码、不带响应体,可简化为:

swagger: "2.0"
info:
  version: 1.0.0
  title: some API
paths:
  /health:
    get:
      operationId: healthCheck
      summary: Health check endpoint
      x-google-backend:
        type: MOCK
      responses:
        '200':
          description: OK

部署该配置后,访问/health端点就会直接返回200状态码,无需依赖任何真实上游服务。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 11:10:19