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

docs: uniCloud hosting

上级 133531d5
......@@ -200,3 +200,6 @@ exports.main = async function(event){
关于云存储:这里的读写次数,并不一定是针对文件的:包括:上传文件、修改Policy、修改ACL、修改CORS 等操作,都会被认为是COS写。环境初始化时也会执行很多次初始化操作,写入 policy/acl/cors 等配置信息。用户每次操作 修改安全域名、修改静态域名等,也会触发 CORS 的写入。
关于数据库:开发者通过uniCloud web控制台访问数据库也会增加少量读写次数
### 部署网站到前端网页托管报“The requested file was not found on this server.”
- 部署history模式的uni-app项目时,如果未修改前端网页托管的配置,直接访问子页面时就会遇到上面的错误。如何配置请参考[部署uni-app项目](uniCloud/hosting.md?id=host-uni-app)
......@@ -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.
先完成此消息的编辑!
想要评论请 注册