我已使用https://github.com/vanister/contacts_api此代码。 我为两个表的Crud操作创建了两个yml差异文件。问题是它只为一张表生成rest-api。我常见的serverless.yml文件代码是
service: contacts-api
provider:
name: aws
runtime: nodejs10.x
stage: dev
region: us-west-2
functions:
- '${file(src/handlers/contacts/contacts.serverless.yml)}'
- '${file(src/handlers/users/users.serverless.yml)}'
plugins:
- serverless-offline
custom:
serverless-offline:
host: 0.0.0.0 # for docker container hosting
contacts.yml
# handler paths are relative to the root serverless.yml file that this is being merged into
# they are also compiled by babel into a 'dist' folder at the root
list:
handler: src/handlers/contacts/list.handler
events:
- http: get /contacts
get:
handler: src/handlers/contacts/get.handler
events:
- http: get /contact/{id}
add:
handler: src/handlers/contacts/add.handler
events:
- http: post /contact
update:
handler: src/handlers/contacts/update.handler
events:
- http: put /contact/{id}
delete:
handler: src/handlers/contacts/delete.handler
events:
- http: delete /contact/{id}
users.yml
# handler paths are relative to the root serverless.yml file that this is being merged into
# they are also compiled by babel into a 'dist' folder at the root
list:
handler: src/handlers/users/list.handler
events:
- http: get /user/getall
get:
handler: src/handlers/users/get.handler
events:
- http: get /user/{id}
add:
handler: src/handlers/users/add.handler
events:
- http: post /user
update:
handler: src/handlers/users/update.handler
events:
- http: put /user/{id}
delete:
handler: src/handlers/users/delete.handler
events:
- http: delete /user/{id}
输出为 无服务器:脱机启动:dev / us-west-2。
无服务器:路由列表: 无服务器:GET / user / getall 无服务器:POST / {apiVersion} / functions / contacts-api-dev-list / invocations
无服务器:获得路线: 无服务器:GET / user / {id} 无服务器:POST / {apiVersion} / functions / contacts-api-dev-get / invocations
无服务器:添加路由: 无服务器:POST /用户 无服务器:POST / {apiVersion} / functions / contacts-api-dev-add / invocations
无服务器:更新路线: 无服务器:PUT /用户/ {id} 无服务器:POST / {apiVersion} / functions / contacts-api-dev-update / invocations
无服务器:删除路由: 无服务器:DELETE / user / {id} 无服务器:POST / {apiVersion} / functions / contacts-api-dev-delete / invocations
无服务器:在http://0.0.0.0:3000上进行离线[HTTP]侦听 无服务器:输入“ rp”以重播上一个请求