2
2
3
3
# 腾讯云 Koa 组件
4
4
5
- [ ![ npm] ( https://img.shields.io/npm/v/%40serverless%2Ftencent-koa )] ( http://www.npmtrends.com/%40serverless%2Ftencent-koa )
6
- [ ![ NPM downloads] ( http://img.shields.io/npm/dm/%40serverless%2Ftencent-koa.svg?style=flat-square )] ( http://www.npmtrends.com/%40serverless%2Ftencent-koa )
7
-
8
- 简体中文 | [ English] ( https://github.com/serverless-components/tencent-koa/blob/master/README.en.md )
5
+ 简体中文 | [ English] ( https://github.com/serverless-components/tencent-koa/blob/v2/README.en.md )
9
6
10
7
## 简介
11
8
@@ -29,7 +26,7 @@ $ npm install -g serverless
29
26
30
27
### 2. 创建
31
28
32
- 本地创建 ` serverless.yml ` 文件和 ` app.js ` 文件:
29
+ 本地创建 ` serverless.yml ` 文件:
33
30
34
31
``` console
35
32
$ touch serverless.yml
@@ -42,10 +39,10 @@ npm init # 创建后持续回车
42
39
npm i --save koa # 安装 koa
43
40
```
44
41
45
- 创建一个 ` app .js` 文件,并在其中创建您的 koa App:
42
+ 创建一个 ` sls .js` 文件,并在其中创建您的 koa App:
46
43
47
44
``` console
48
- $ touch app .js
45
+ $ touch sls .js
49
46
```
50
47
51
48
``` js
@@ -71,26 +68,27 @@ module.exports = app
71
68
``` yml
72
69
# serverless.yml
73
70
74
- koa :
75
- component : ' @serverless/tencent-koa'
76
- inputs :
77
- region : ap-guangzhou
78
- functionName : koa-function
79
- runtime : Nodejs8.9
80
- code : ./
81
- functionConf :
82
- timeout : 10
83
- memorySize : 128
84
- environment :
85
- variables :
86
- TEST : vale
87
- apigatewayConf :
88
- protocols :
89
- - https
90
- environment : release
71
+ org : orgDemo # (optional) serverless dashboard org. default is the first org you created during signup.
72
+ app : appDemo # (optional) serverless dashboard app. default is the same as the name property.
73
+ stage : dev # (optional) serverless dashboard stage. default is dev.
74
+ component : koa # (required) name of the component. In that case, it's koa.
75
+ name : koaDemo # (required) name of your koa component instance.
76
+
77
+ inputs :
78
+ src :
79
+ src : ./src # (optional) path to the source folder. default is a hello world app.
80
+ exclude :
81
+ - .env
82
+ region : ap-guangzhou
83
+ runtime : Nodejs10.15
84
+ apigatewayConf :
85
+ protocols :
86
+ - http
87
+ - https
88
+ environment : release
91
89
` ` `
92
90
93
- - [点击此处查看配置文档](https://github.com/serverless-components/tencent-koa/blob/master /docs/configure.md)
91
+ - [点击此处查看配置文档](https://github.com/serverless-components/tencent-koa/blob/v2 /docs/configure.md)
94
92
95
93
### 4. 部署
96
94
101
99
> 注:`sls`命令是`serverless`命令的缩写
102
100
103
101
```
104
- $ sls --debug
105
-
106
- DEBUG ─ Resolving the template's static variables.
107
- DEBUG ─ Collecting components from the template.
108
- DEBUG ─ Downloading any NPM components found in the template.
109
- DEBUG ─ Analyzing the template's components dependencies.
110
- DEBUG ─ Creating the template's components graph.
111
- DEBUG ─ Syncing template state.
112
- DEBUG ─ Executing the template's components graph.
113
- DEBUG ─ Generating serverless handler...
114
- DEBUG ─ Generated serverless handler successfully.
115
- DEBUG ─ Compressing function koa-function file to /Users/yugasun/Desktop/Develop/serverless/tencent-koa/example/.serverless/koa-function.zip.
116
- DEBUG ─ Compressed function koa-function file successful
117
- DEBUG ─ Uploading service package to cos[ sls-cloudfunction-ap-guangzhou-code] . sls-cloudfunction-default-koa-function-1584364164.zip
118
- koa-function [ ████████████████████████████████████████] 100% | ETA: 0s | Speed: 923.87k/s
119
- DEBUG ─ Uploaded package successful /Users/yugasun/Desktop/Develop/serverless/tencent-koa/example/.serverless/koa-function.zip
120
- DEBUG ─ Creating function koa-function
121
- DEBUG ─ Updating code...
122
- DEBUG ─ Updating configure...
123
- DEBUG ─ Created function koa-function successful
124
- DEBUG ─ Setting tags for function koa-function
125
- DEBUG ─ Creating trigger for function koa-function
126
- DEBUG ─ Deployed function koa-function successful
127
- DEBUG ─ Starting API-Gateway deployment with name ap-guangzhou-apigateway in the ap-guangzhou region
128
- DEBUG ─ Using last time deploy service id service-pnlxadhq
129
- DEBUG ─ Updating service with serviceId service-pnlxadhq.
130
- DEBUG ─ Endpoint ANY / already exists with id api-9415bswy.
131
- DEBUG ─ Updating api with api id api-9415bswy.
132
- DEBUG ─ Service with id api-9415bswy updated.
133
- DEBUG ─ Deploying service with id service-pnlxadhq.
134
- DEBUG ─ Deployment successful for the api named ap-guangzhou-apigateway in the ap-guangzhou region.
135
-
136
- koa:
137
- functionName: koa-function
138
- functionOutputs:
139
- ap-guangzhou:
140
- Name: koa-function
141
- Runtime: Nodejs8.9
142
- Handler: serverless-handler.handler
143
- MemorySize: 128
144
- Timeout: 10
145
- Region: ap-guangzhou
146
- Namespace: default
147
- Description: This is a template function
148
- region: ap-guangzhou
149
- apiGatewayServiceId: service-pnlxadhq
150
- url: https://service-pnlxadhq-1251556596.gz.apigw.tencentcs.com/release/
151
- cns: (empty array)
152
-
153
- 36s › koa › done
102
+ $ sls deploy
154
103
```
155
104
156
105
部署完毕后,可以在浏览器中访问部署成功地 url。
@@ -160,14 +109,7 @@ $ sls --debug
160
109
通过以下命令移除部署的 Koa 服务。
161
110
162
111
```
163
- $ sls remove --debug
164
-
165
- DEBUG ─ Flushing template state and removing all components.
166
- DEBUG ─ Removed function koa-function successful
167
- DEBUG ─ Removing any previously deployed API. api-9415bswy
168
- DEBUG ─ Removing any previously deployed service. service-pnlxadhq
169
-
170
- 14s › koa › done
112
+ $ sls remove
171
113
```
172
114
173
115
### 账号配置(可选)
0 commit comments