0.0.2 • Published 4 years ago

towify-template-multiple-routes-scf v0.0.2

Weekly downloads
2
License
ISC
Repository
-
Last release
4 years ago

towify-single-scf-template

1.实现代码

1.1 定义handler class

需要校验token的 extends UserAuthedRestApiBaseHandler
无需校验token的 extends UserNoAuthRestApiBaseHandler

1.2 实现handle() 和 validateParams()

2.配置路由

在src/route.ts中添加路由配置,例如:

 addRoute('/dev/userInfo', HttpMethod.GET, new UserInfoHandler());

tips: 路由的第一级需要和serverless.yml中的 api网关path保持一致

3.启动本地开发local server

npm run local

tips: 修改.env.dev中的LOCAL_SERVER_PORT可以配置local server端口号;目前local server只支持params和body传参,未支持路径参数

4.发布

npm run deploy_dev

tips: 该模板发布采用了无layer配置项的做法(把node_module发布上去,此时无需配置layers),如果只想发布dist中的js代码,请修改serverless.yml中的 inputs.src为 ./dist 同时配置layers

5.线上url

5.1 线上dev环境

http://sls-api-dev.towify.com/your_api_path