提交 be588958 编写于 作者: 雪洛's avatar 雪洛

docs: uniCloud hosting

上级 419d1e44
......@@ -165,3 +165,7 @@ uniCloud服务商为阿里云时支持配置全球加速,步骤如下:
4. 选择不使用的账号登录之后注销即可,参考文档:[注销腾讯云账号](https://cloud.tencent.com/document/product/378/30253)
同时,如果付费购买腾讯云服务空间,每个账号可以最多拥有50个腾讯云服务空间(注意其中仅有一个享受免费额度)。
### 部署网站到前端网页托管报“The requested file was not found on this server.”
- 部署history模式的uni-app项目时,如果未修改前端网页托管的配置,直接访问子页面时就会遇到上面的错误。如何配置请参考[部署uni-app项目](uniCloud/hosting.md?id=host-uni-app)
\ No newline at end of file
......@@ -151,6 +151,21 @@ uni.request({
+ 请求Body大小限制,不能超过1M。
+ 响应Body大小限制,不能超过1M。
云函数接收到的post请求的请求体可能是被转成base64的,如果是这样需要进行一次转化。
以接收application/json格式的post请求为例
```js
exports.main = function(event) {
let body = event.body
if(event.isBase64Encoded){
body = Buffer.from(body)
}
const param = JSON.parse(body) // param为客户端上传的数据
// ...
}
```
### 云函数的返回值
......@@ -160,7 +175,7 @@ uni.request({
云函数返回字符串,那么:
```js
module.exports.main = function() {
exports.main = function() {
return 'hello gateway'
}
```
......@@ -180,7 +195,7 @@ hello gateway
返回的`Object`会被转换为 JSON,同时 HTTP 响应的`content-type`会被设置为 `application/json`
```js
module.exports.main = function() {
exports.main = function() {
return {
foo: 'bar'
}
......@@ -216,7 +231,7 @@ content-length: 13
`content-type`设置为`text/html`,即可在`body`中返回 HTML,会被浏览器自动解析:
```js
module.exports.main = function() {
exports.main = function() {
return {
mpserverlessComposedResponse: true, // 使用阿里云返回集成响应是需要此字段为true
statusCode: 200,
......@@ -243,7 +258,7 @@ content-length: 14
`content-type`设置为`application/javascript`,即可在`body`中返回 JavaScript 文件:
```js
module.exports.main = function() {
exports.main = function() {
return {
mpserverlessComposedResponse: true, // 使用阿里云返回集成响应是需要此字段为true
statusCode: 200,
......@@ -270,7 +285,7 @@ console.log("Hello!")
如果返回体是诸如图片、音视频这样的二进制文件,那么可以将`isBase64Encoded`设置为`true`,并且将二进制文件内容转为 Base64 编码的字符串,例如:
```js
module.exports.main = function() {
exports.main = function() {
return {
mpserverlessComposedResponse: true, // 使用阿里云返回集成响应是需要此字段为true
isBase64Encoded: true,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册