tps*_*idt 6 amazon-web-services aws-api-gateway serverless-framework
由于与 REST 网关相比价格大幅降低,我对 HTTP 网关感到非常兴奋,但我坚持创建不会完全破坏我的serverless.yml文件的路由。
Serverless 的 HTTP 网关文档描述了这一点来定义路由:
functions:
params:
handler: handler.params
events:
- httpApi:
method: GET
path: /get/for/any/{param}
Run Code Online (Sandbox Code Playgroud)
支持'*',但这会导致问题,OPTIONS因为这些会覆盖创建的 CORS 策略(因此 OPTIONS 请求实际上会到达应用程序,这没有任何意义,尤其是在路由通过授权者保护的情况下)。
此外,不可能定义多个方法。
# does not work
method: GET,POST,DELETE
# also not possible
method:
- GET
- POST
- DELETE
Run Code Online (Sandbox Code Playgroud)
我发现的唯一配置是分别定义所有路由:
events:
- httpApi:
path: /someApi/{proxy+}
method: GET
- httpApi:
path: /someApi/{proxy+}
method: POST
- httpApi:
path: /someApi/{proxy+}
method: DELETE
Run Code Online (Sandbox Code Playgroud)
这很好用,用户界面甚至捆绑了路由,因为它们位于相同的前缀路径上:
但是有了这个,我必须为我的所有主要资源分别定义所有 HTTP 方法,包括附加的授权方。
有没有办法把它结合起来?
| 归档时间: |
|
| 查看次数: |
486 次 |
| 最近记录: |