Skip to main content

Static Website Hosting

CloudBase provides developers with the capability of static website hosting. The distribution of static resources (HTML, CSS, JavaScript, fonts, etc.) is supported by object storage COS and a CDN with multiple edge locations. You can deploy static websites in the Tencent Cloud console and make them accessible to your users. Currently, the static website hosting capability of CloudBase is only supported in the Tencent Cloud CloudBase console, and not yet available in the Mini Program IDE console.

Only environments with a pay-as-you-go payment method can enable static website hosting capability; environments with a prepaid payment method cannot.

For the static website hosting capability of CloudBase, when creating an environment, the static website hosting service is not automatically enabled; instead, you need to manually enable it in the environment.

Notes

Before using the CLI to operate the static website hosting service, please go to the CloudBase console to enable the static website hosting service.

Full Deployment

CloudBase CLI provides a command to deploy website files directly. In the directory of the folder you want to deploy, simply run the tcb hosting deploy command to deploy all files in the current directory to the static website hosting.

For example

# docs Build Directory
cd docs
# Deploy All Files
tcb hosting deploy -e envId

Deploy Files

You can also specify files/folders and upload them to a specified path in the static website using the CLI. When cloudPath is not specified, files will be uploaded to the root directory.

# Deploy Files to Specified Directory
tcb hosting deploy localPath cloudPath -e envId
# Deploy All Files in the hosting Directory to the Root Directory
tcb hosting deploy hosting -e envId

# Deploy the index.js file in the static directory to static/index.js
tcb hosting deploy ./static/index.js static/index.js -e envId
⚠️ Note

When using vue.history mode, you need to configure the error page in the Static Website-settings to point to the page your app depends on.

The theoretical maximum size for a single deployed file is 50TB with no limit on the number of files, subject to actual conditions.

If you have a large number of files, the upload may fail with the error { message: 'socket hang up', code: 'ECONNRESET' }. It is recommended to execute export COS_SDK_KEEPALIVE=false before running tcb hosting deploy, as this command will disable SDK keep-alive connections.

Service Information

You can use the following command to display the static website's status, access domain, and other information.

tcb hosting detail -e envId

Deleting Files

You can use the following command to delete files or folders in the storage space of your static website.

tcb hosting delete cloudPath -e envId

Delete All Files

When the cloud path is empty, it means all files will be deleted.

tcb hosting delete -e envId

Listing Files

You can use the following command to deploy and display files in the static website storage space.

tcb hosting list -e envId

About Path

  • localPath is the path of a local file or folder, in the form of directory/filename, such as ./index.js, static/css/index.css, etc.
  • cloudPath is the path of the file or folder relative to the root directory, in the form of directory/filename, such as index.js, static/css/index.js, etc.
Note

In Windows systems, localPath follows the local path format, which is recognizable by the system and typically uses the \ separator. cloudPath is a cloud file path and must use the / separator.