Skip to content

Commit aa64092

Browse files
committed
docs: update readme
1 parent 0546d8f commit aa64092

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,26 @@ TENCENT_SECRET_ID=123
102102
TENCENT_SECRET_KEY=123
103103
```
104104

105+
## 静态资源服务
106+
107+
如果想要支持返回静态资源,比如图片之类的,需要在入口文件 `sls.js` 中指定相关 `MIME` 类型的文件为二进制,这样云函数在返回请求结果给 API 网关是,会对指定类型进行 `Base64` 编码,最终返回给客户端才能正常显示。如下:
108+
109+
```js
110+
const koa = require('koa')
111+
const app = koa()
112+
113+
// Routes
114+
// ...
115+
116+
app.binaryTypes = ['*/*']
117+
118+
module.exports = app
119+
```
120+
121+
`['*/*']` 代表所有文件类型将进行 `Base64` 编码,如果需要定制化,可以配置为 `['image/png']`,意思是指定 `png` 格式的图片类型。
122+
123+
更多文件类型的 `MIME` 类型,可参考 [mime-db](https://github.com/jshttp/mime-db/blob/master/db.json)
124+
105125
### slsInitialize 应用初始化
106126

107127
有些时候,Koa 服务在启动前,需要进行一个初始化操作,比如数据库建连,就可以通过在 Koa 实例对象上添加 `slsInitialize` 函数来实现,如下:

0 commit comments

Comments
 (0)