WeDa & CloudBase
WeDa is built on CloudBase. Most capabilities of CloudBase are fully functional in WeDa, and most components of WeDa applications have corresponding counterparts in CloudBase.
WeDa Module | CloudBase Counterpart |
---|---|
Application (WEB Frontend) | Static Hosting, stored in the path /app-xxxxxxx according to the application IDLogin page is stored in the /__auth directory |
Resources | Static Hosting, storage path: /resources |
Image/File Upload Component | Cloud Storage, storage path: /weda-uploader |
Custom Domain | HTTP Access Service |
APIs Custom Code | Cloud Function Published function: lowcode-datasource Test/Preview function: lowcode-datasource-preview |
Data Model | Database/ MySQL Published database: lcap-[datasource-id]-[datasource-identifier] Development/Preview database: lcap-[datasource-id]-[datasource-identifier]-preview No corresponding counterpart in CloudBase for MySQL |
User/Login Method | User/Login Authorization |
Enterprise Workspace/Data Management | Static Hosting, storage path: /adminportal |
The following will introduce the capabilities of using Cloud Development in WeDa from both design-time and runtime perspectives.
Design-time
Each WeDa environment corresponds to a Cloud Development environment. Based on the mapping relationship between WeDa modules and Cloud Development, accessing the Cloud Development console allows self-service configuration adjustments for applications and services, as well as viewing request logs for APIs custom code cloud functions. For example, accessing the Cloud Development console enables the following advanced operations:
Application (WEB frontend)/Resources - Cloud Development Static Hosting
- Customizing caching policies for static hosting
- Manually adding static files, such as self-service uploads of static files, verification files, and custom pages that cannot be uploaded via the resources section
- Manually taking down the web part of an application by removing its file directory
Images/Files Upload - Cloud Development Cloud Storage
- Customizing caching policies for user-uploaded files by modifying cloud storage configuration
- Adjusting access permission policies
APIs Custom Code - Cloud Development Cloud Function
- Viewing execution logs for APIs custom code via cloud functions
- Adjust the timeout for APIs custom code via cloud functions (the maximum duration for the frontend to receive a return value is 60 seconds)
- Setting up a fixed IP for external requests from APIs custom code via cloud functions
- Alternatively, you can add dependencies by configuring the
dependencies
field in the cloud function's package.json for use in custom code - Use cloud function provisioned concurrency to improve APIs custom code performance or handle sudden traffic spikes
- Self-built cloud functions implement certain custom capabilities
Data Model - CloudBase Database/ MYSQL
- MYSQL has no corresponding carrier in CloudBase
- Performing data rollback via CloudBase Database
- Manually add an index
Custom Domain - CloudBase HTTP Access Service
- Extend custom domain access routing via HTTP Access Service
Please exercise caution when modifying the resource configurations of the WeDa environment in the Cloud Development console, and ensure you understand the potential consequences of your actions!
How to access the Cloud Development console for the WeDa environment?
There are two ways to access the Cloud Development console for the WeDa environment:
Access the Cloud Development Legacy Console, select the environment corresponding to WeDa to enter (the environment ID prefix is
lowcode-
).First, locate the
envId
of the WeDa environment. It can typically be obtained by checking theenvId
parameter in the WeDa console or application editor, or found in the basic settings of the application details. Then directly replace the envId parameter in the URL with your environment's:https://console.cloud.tencent.com/tcb/env/overview?envId=lowcode-xxxxxx&rid=4
Runtime
Beyond the capabilities provided by WeDa, CloudBase offers additional rich service capabilities. Simply put, in the application frontend of WeDa, custom code in APIs, or cloud functions, you can extend WeDa's capabilities through the relevant CloudBase SDK.
In the application frontend, you can obtain the application instance after initializing the CloudBase js-sdk using the $w.cloud.getCloudInstance
method. Through this instance, you can invoke various CloudBase capabilities such as cloud functions, cloud storage, and database (note: model applications currently cannot directly use database capabilities in the frontend).
For example, directly call a custom cloud function in the application frontend custom code:
export default async function ({ event, data }) {
const app = await $w.cloud.getCloudInstance();
// Before calling the custom cloud function, you need to create and implement it in the CloudBase console.
// is equivalent to $w.cloud.callFunction
const { result } = await app.callFunction({
name: "myFunction",
data: {
key: 1,
},
});
console.log(result);
}
In APIs custom code, you can obtain the CloudBase nodeSDK reference via context.cloudbase
and get the instantiated instance via context.app
. Refer to the context documentation.
For example, in APIs custom code, you can also call custom cloud functions:
module.exports = async function (params, context) {
const { app } = context;
// Before calling the custom cloud function, you need to create and implement it in the CloudBase console.
const { result } = await app.callFunction({
name: "myFunction",
data: {
key: 1,
},
});
console.log(result);
};
You can also implement transaction and aggregation capabilities through the Transaction and Aggregation interfaces. In summary, by using the CloudBase SDK or APIs, you can extend CloudBase's powerful capabilities to WeDa to achieve more diverse functionalities.