# Introduction

A service space corresponds to a set of independent cloud development resources, including databases, storage spaces, cloud functions and other resources. Service spaces are isolated from each other.

Each service space has a globally unique space ID.

  • Manage service spaces through HBuilderX, including new service spaces and associated service spaces

Create a service space in the uniCloud directory context menu

After creating a service space, associate the service space in the same uniCloud directory context menu. Only after the project is associated with the service space, you can upload cloud functions, operate the database, storage and other resources under the service space.

The web console can create and delete service spaces and manage online service space resources.

Note for new service space

  • When you create a Tencent Cloud service space for the first time, a Tencent Cloud account will be created for the user and the user will be redirected to the Tencent Cloud real-name interface. The service space can be opened after the real-name verification and verification. If Tencent Cloud real-name authentication indicates that too many accounts have been created under the ID card, you need to cancel the unused accounts on the Tencent Cloud official website. See details
  • It may take dozens of seconds to create a service space. You can check whether the creation is complete in the web console.

# Collaboration

Before July 18, 2022, the multi-person collaboration in the service space is set up in the app collaboration on dev.dcloud.net.cn. After July 18, 2022, set it on unicloud.dcloud.net.cn instead.

A service space has only one creator, but collaboration members can be set.

When the project involves multi-person development, set up collaborators (select service space -> member management) in the uniCloud WEB console, so that multiple people can use one cloud service space together.

Collaborators can operate authorized service spaces in HBuilderX and the web console. Except for deleting service spaces, other functions can operate normally.

Authorization steps:

  1. Log in to the uniCloud WEB console and select the service space where you want to add collaborators
  2. On the left menu of the service space details page, click Member Management
  3. Enter the collaborator's email and click 'Search', the search results will appear below, and click 'Add member' to add after confirming that it is correct

成员管理

  1. You can view and remove the added collaborators in the member list below

成员列表

Notice

  • The service space collaborator and the app collaborator are two sets of systems, which need to be set separately and are not related. App collaborators are set up at dev.dcloud.net.cn.
  • Only the creator of the service space can add members, collaborators do not have this permission
  • According to legal requirements, collaborator accounts need to complete real-name authentication before they can be added normally

# The relationship between application and service space

Each uni-app application has an appid, and each service space has a spaceid.

The service space and the mobile terminal project are in a many-to-many binding relationship. Under the same DCloud account, an application can be associated with multiple service spaces. A service space can also be accessed by multiple projects.

# Multi-app shared service space

As more and more projects developed by users using uniCloud, some users encountered new problems.

Two or more projects want to share a cloud service space. For example, a system has a client project and an admin project. The two projects need a public service space. There are also the driver side, the passenger side, the user side, the rider side... Many similar problems.

If there are multiple duplicate cloud function files in each project directory. Every project needs to do operations such as synchronizing the cloud function list and downloading cloud functions. Cumbersome and prone to conflict.

In response to the above problems, a solution of one cloud with multiple projects is provided.

# One cloud and multiple terminals

# Bind the service space of other projects

选中项目下的uniCloud-alipay|aliyun|tcb目录, 右键菜单,点击 【关联云服务空间或项目... 】 ,可以关联云服务空间绑定其它项目的服务空间

# Associated Projects

Select the associated project, all uniapp projects are displayed at this time. The user selects any uniapp item to associate, and the association effect is as follows:

  1. View the service space of the associated project: After clicking, the associated project will be opened in the project manager
  2. Unbind: Unbinding will unbind the relationship. You can re-associate the cloud service space, bind the service space of other projects
  3. Move to the associated project xxx: The contents of the uniCloud directory of the current project will be moved to the associated project.
# Plugins Market Import Plugins

# Special Note

Taking Alibaba Cloud as an example, Bind the service space of other projects refers to the currently used Alibaba Cloud service space associated with other projects.

  1. Alibaba Cloud cannot be associated with Tencent Cloud, and Tencent Cloud cannot be associated with Alibaba Cloud, but the project can be associated, and an error will be reported when using it.
  2. If the project is associated with other projects, select the cloud service space, and the association will be disconnected.

# One application accesses multiple service spaces

If the application only connects to one service space, you can do the service space association in HBuilderX. Developers do not need to manually do initialization work (which can be understood as class calls).

//The project is only connected to one service space, so there is no need to initialize
//The API developed by the cloud can be called directly through uniCloud
uniCloud.callFunction()
uniCloud.uploadFile()

If an application needs to connect more service spaces at the same time, more service spaces cannot be bound in HBuilderX. At this time, the developer needs to manually call the initialization method uniCloud.init in the client code to connect to other service spaces.

The uniCloud.init method will return an uniCloud instance, and all subsequent cloud function API calls need to be initiated through the uniCloud instance (similar to instance calls).

The uniCloud.init method is defined as follows:

function init(options):uniCloud

The uniCloud.init method accepts an options parameter and returns an uniCloud instance, which can call cloud functions and cloud storage related APIs.

Notice

  • Cloud functions will automatically identify the service space to which they belong, and do not need to be initialized when calling resources in this service space.
  • The cloud function environment (only supported by Tencent Cloud) can only return other Tencent Cloud service space instances under the same account through init.
  • The client environment (supported by Tencent Cloud and Alibaba Cloud) can return to any cloud vendor service space instance under the account through init

options parameter description

参数名 类型 必填 默认值 说明
provider String - aliyun、tencent、alipay
spaceId String - 服务空间ID,注意是服务空间ID,不是服务空间名称
clientSecret String - 仅阿里云支持,可以在uniCloud控制台服务空间列表中查看
accessKey String - 仅支付宝小程序云支持, 可以在uniCloud控制台服务空间详情中查看
secretKey String - 仅支付宝小程序云支持, 可以在uniCloud控制台服务空间详情中查看
spaceAppId String - 仅支付宝小程序云支持, 可以在uniCloud控制台服务空间详情中查看
endpoint String 阿里云:https://api.bspapp.com
支付宝小程序云:https://{spaceId}.api-hz.cloudbasefunction.cn
服务空间地址,仅阿里云与支付宝小程序云支持。
阿里云商用版请将此参数设为https://api.next.bspapp.com

Sample code

// If the developer creates multiple service spaces, it needs to be initialized manually. Note that this is front-end code, not cloud function code
const myCloud = uniCloud.init({
  provider: 'aliyun',
  spaceId: 'xxxx-yyy',
  clientSecret: 'xxxx'
});
//Call the API developed by the cloud through the uniCloud instance
myCloud.callFunction()
myCloud.uploadFile()

uniCloud还支持跨服务空间的数据库访问,另见文档