# uniCloud发行

After local development and debugging, be sure to upload it to the uniCloud service space to take effect on the live network.

Distribution is divided into cloud resource distribution and client distribution.

# Cloud resource distribution

Various cloud functions and DB Schemas need to be uploaded and released.

HBuilderX has a variety of distribution methods

  • Issue menu
  • Right-click various files in the uniCloud directory to upload. The shortcut key is [Ctrl+u]
  • Right-click on the uniCloud directory to start the uniCloud service space initialization wizard

# 小程序中使用uniCloud

Each applet platform requires the configuration of the network server domain name of the applet application in the applet management background, otherwise it will not be able to connect to the Internet.

After using uniCloud, developers no longer need to purchase and record domain names by themselves, and can directly fill in the uniCloud domain name in the applet management background. (If you need to use front-end web hosting, you still need to file a domain name)

According to the following table, set the request legal domain name and uploadFile legal domain name in the applet management background (if there is no file upload business, you can not set it). The domain names in the following table are all owned by Alibaba Cloud or Tencent Cloud, not DCloud.

服务提供商 request合法域名 uploadFile合法域名 download合法域名
阿里云 api.next.bspapp.com 请在uniCloud web控制台服务空间的总览页面查看 请在uniCloud web控制台服务空间的总览页面查看
腾讯云 tcb-api.tencentcloudapi.com cos.ap-shanghai.myqcloud.com (2023年8月17日腾讯云更新了上传域名,如果遇到小程序因为安全域名无法上传的问题可以把小程序开发工具内提示的不在白名单的域名添加到上传安全域名内) 需要从云存储下载文件的时候才需要配置,不同服务空间域名不同,可以在web控制台查看文件详情里面看到
支付宝小程序云 {spaceId}.api-hz.cloudbasefunction.cn https://u.object.cloudrun.cloudbaseapp.cn {spaceId}.normal.cloudstatic.cn

Notice

  • If you need to use uni.request to request files in the cloud storage, you need to configure the cloud storage domain name (that is, the download legal domain name in the above table) to the request legal domain name
  • 阿里云迁移正式版后未重新发布的项目仍会请求公测版地址(api.bspapp.com)
  • 如果项目使用了uni-push,还需要将uni-push的socket域名添加到白名单详情查看
  • 支付宝小程序云的域名是动态的,需要在小程序管理后台配置{spaceId}.api-hz.cloudbasefunction.cn,其中{spaceId}是服务空间的id,可以在uniCloud web控制台的服务空间总览页面查看

Alibaba cloud view upload and download security domain name

阿里云查看上传、下载安全域名

For the real machine preview function of the applet development tool, the above-mentioned domain name whitelist must be added, otherwise the cloud function cannot be called. The PC-side preview and real-device debugging of the simulator are not affected by this.

If you encounter a valid domain name configured correctly but still report url not in domain list, please try to delete the applet on the phone, clear the client cache where the applet is located, restart the corresponding applet development tool and try again

If you encounter invalid ip xxx, not in whitelist, please check whether the domain name whitelist is enabled in the MiniApp management background. If it is not used, it can be closed. If you confirm that you need to use the ip whitelist, please refer to: Fixed IP

About the use of the cloud function local debugging service in the applet

When you use the run menu in HBuilderX to run to the applet, it will connect to the local debugging service. Even if you choose to connect to the cloud cloud function before running, the applet will send a request to the local debugging service to detect whether the cloud function is called locally or in the cloud.

**It is recommended to ignore domain name verification directly in development mode. **

即使在开发工具勾选了忽略域名校验,体验版与正式版不会忽略域名校验。如果要发布体验版正式版,请务必在HBuilderX内使用发行菜单。uni-app项目发行与运行输出的目录不同,请注意不要选错了

# 已经加了白名单,但小程序体验版和正式版还是无法请求云函数

请务必在HBuilderX内使用【发行】菜单打包小程序,【运行】菜单打包的代码只能用于本地调试,【发行】菜单打包的代码才能发布体验版和正式版。

如果域名白名单提示 127.0.0.1 这个ip没有加入白名单,那代表你点的就是【运行】菜单发布的体验版,请务必点【发行】发布小程序。uni-app项目发行与运行输出的目录不同,请注意不要选错了

# Web端使用uniCloud

The domain name of the cloud function is bspapp.com or tencentcloudapi.com. But the developer's web front-end must be deployed under other domain names (including unicloud's front-end web page hosting). Then the web front-end js accessing the cloud function involves cross-domain issues, which makes the front-end js unable to connect to the cloud function server.

At this time, you need to operate in the background of uniCloud to bind a secure domain name to the cloud function. If the js of the front-end web page under which domain name wants to access the cloud function, configure the domain name. If you use unicloud front-end web page hosting, no matter if you have your own test domain name or a developer’s domain name, as long as you want to access cloud functions, you must configure the domain name here.

注意跨域配置需要带上端口信息。例如:前端页面运行于:www.xxx.com:5001,跨域配置内配置:www.xxx.com不会对此页面生效,需要配置为:www.xxx.com:5001,端口部分也支持通配符

If you want to break through the cross-domain restrictions during runtime, there are the following solutions:

  • When running to the Web side, use the built-in browser of HBuilderX to ignore cross-domain issues.

  • If you want to use an external browser to run when running, the scheme is as follows:

    • Method 1: Bind the address in the uniCloud web console to a secure domain name during the test period, such as configuration: localhost:8080, 192.168.0.1:8080 (it is recommended to use the built-in browser for testing directly)
    • Method 2: Install cross-domain plug-ins in external browsers, see: https://ask.dcloud.net.cn/article/35267 . For cross-domain addresses, see the section on configuring secure domain names for Mini Programs in the above document.
  • 2021年9月16日之前阿里云跨域配置不对云存储及前端网页托管生效,表现为云存储中图片绘制到canvas会污染画布,前端网页托管的网页不可在iframe中使用。

  • 2021年9月16日之后阿里云跨域配置可以对前端网页托管生效,仅对前端网页托管的自定义域名生效,不对默认域名生效,如何绑定自定义域名请参考:前端网页托管绑定自定义域名,设置之后可能需要几分钟才会生效。如果你在之前已经设置了跨域域名和前端网页托管的自定义域名,需要重新设置一次跨域域名才能生效。

  • 2022年12月2日阿里云正式版跨域配置支持使用通配符,限制配置9个跨域域名。正式版默认允许localhost跨域

  • 2023年2月3日阿里云正式版跨域配置对云存储生效,如果此前已配置跨域配置下次进行修改时会同步设置到云存储。

注意

  • 跨域配置同时对云函数、前端网页托管、云存储生效
  • 阿里云云存储默认不支持localhost跨域,如有需求请添加127.0.0.1:*到跨域配置内
  • 访问云存储文件时,如果客户端存在缓存,可能会出现已配置跨域域名的情况下仍然跨域的问题。建议这种场景下在请求头内加上{"cache-control": "no-cache","pragma": "no-cache"}

# Client resource distribution

# Front-end web hosting

uniCloud supports front-end static web page hosting, click the release menu in HBuilderX, generate Web, and deploy the generated front-end files in the front-end web page hosting of uniCloud For details, refer to.

It should be noted that you still need to configure the binding security domain name in uniCloud web console (see the previous chapter), so that the js of the front-end web page can access the cloud function.

# App Upgrade Center

uniCloud integrates cloud-integrated upgrade detection and management-side version maintenance. See details

# Application unified release page

App, applet, web unified publishing page. See details

##cli release

During large-scale development, it is often necessary to issue through the command line for continuous integration.

HBuilderX provides cli, see details