We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5c66613 commit be7b170Copy full SHA for be7b170
README.md
@@ -155,6 +155,26 @@ TENCENT_SECRET_ID=123
155
TENCENT_SECRET_KEY=123
156
```
157
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
178
## License
179
180
MIT License
0 commit comments