我需要一个非常安全的云功能,所以我试图把它放在 API 网关后面。当我直接在标头中传递 Bearer 令牌时,该函数工作正常:
https://us-central1-<my-project>.cloudfunctions.net/<my-hello-function>
但是我想允许它通过 API 网关与 API 令牌一起使用(然后做一些比说“你好”更有用的事情):
https://my-gateway-xxxxxxxx.uc.gateway.dev/v1/stats&key=<my-API-token>
当我尝试调用它时,我得到:
{ "code": 404, "message": "路径不匹配任何需求 URI 模板。" }
我的 API 网关配置文件:
swagger: "2.0"
info:
title: my-gateway
version: "1.0.0"
basePath: "/v1"
schemes:
- "https"
produces:
- application/json
paths:
/stats:
get:
tags:
- "stats"
summary: "get service stats"
description: "Returns statistics"
operationId: "hello_world"
#produces:
#- "application/json"
parameters:
- name: "since"
in: "header"
description: "Date to retrieve information"
required: false
type: "string"
format: "date"
x-google-backend:
address: https://us-central1-<my-project>.cloudfunctions.net/<my-hello-function>
path_translation: CONSTANT_ADDRESS
protocol: h2
responses:
"200":
description: "successful operation"
schema:
$ref: "#"
"400":
description: "Invalid datetime supplied"
"404":
description: "Unknown path"
security:
- api_key: []
securityDefinitions:
api_key:
type: "apiKey"
name: "api_key"
in: "query"
definitions:
ApiResponse:
type: "object"
properties:
code:
type: "integer"
format: "int32"
type:
type: "string"
message:
type: "string"
少了什么东西?我究竟做错了什么?