Skip to content

Commit be7b170

Browse files
committed
docs: update readme
1 parent 5c66613 commit be7b170

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
@@ -155,6 +155,26 @@ TENCENT_SECRET_ID=123
155155
TENCENT_SECRET_KEY=123
156156
```
157157

158+
## 静态资源服务
159+
160+
如果想要支持 `express.static()` 返回静态资源,比如图片之类的,需要在入口文件 `sls.js` 中指定相关 `MIME` 类型的文件为二进制,这样云函数在返回请求结果给 API 网关是,会对指定类型进行 `Base64` 编码,最终返回给客户端才能正常显示。如下:
161+
162+
```js
163+
const express = require('express')
164+
const app = express()
165+
166+
// Routes
167+
// ...
168+
169+
app.binaryTypes = ['*/*']
170+
171+
module.exports = app
172+
```
173+
174+
`['*/*']` 代表所有文件类型将进行 `Base64` 编码,如果需要定制化,可以配置为 `['image/png']`,意思是指定 `png` 格式的图片类型。
175+
176+
更多文件类型的 `MIME` 类型,可参考 [mime-db](https://github.com/jshttp/mime-db/blob/master/db.json)
177+
158178
## License
159179

160180
MIT License

0 commit comments

Comments
 (0)