Unlock 1 Year of EdgeOne + 1TB CDN: Join Our Developer Journey
Get Started Now !
EdgeOne CLI
Overview
Edgeone CLI provides methods to manage Pages Functions and the ability for fast deployment. With the CLI, you can generate, configure, and debug functions in a project, and also upload the built product to the Pages platform in the form of a folder or Zip package.
Preparations
Use a Gmail account to quickly register and log in to the Tencent Cloud Console.
Activate Pages Service in the console, create a new Pages Project, and clone it to local.
Quick Start
1. Installing
In the cloned project during the preparation stage, you can install the CLI using npm:
npm install -g edgeone
Check whether the installation was successful by using the
edgeone -v
command. View all related commands by using the edgeone -h
command.
2. Logging In
Execute the login command, select
Global
(International) or China
as prompted. It is recommended to select Global
to ensure accurate data and information are obtained, and then complete the login in the pop-up browser window.edgeone login
After completing the login, you can execute
edgeone whoami
to view the information of the current logged-in account.
3. Initializing
After a successful login, execute the initialization command. To initialize the basic environment required for Edgeone Pages in the project:
edgeone pages init
After initialization is completed, a
functions
folder and sample functions will be generated under the project root directory. Subsequently, you can continuously add and develop functions in this folder. For detailed usage of the functions, refer to the documentation.
4. Developing Locally
After initialization is completed, enter the local development stage:
edgeone pages dev
The command runs by default and starts a service on the local port 8088. You can access the sample function via
http://localhost:8088/helloworld
. The access path here is the address path of the function file in the functions
folder.
During local development, the service of a Pages Function and the service of a Pages Project may run on different ports. To enable the Pages Project to invoke functions, you can use a proxy server or reverse proxy to forward requests to the correct port. The following is an example of configuration for webpack-dev-server:
module.exports = {devServer: {proxy: {'/api': {target: 'http://localhost:8088', // Local development service address of Pages FunctionchagneOrigin: true,pathRewrite: {'^/api': '',}}}}}
This way, use the Fetch API in the Pages Project:
fetch('/api/my-functions', {method: 'POST',body: JSON.stringify({ data: 'example' }),})
5. Associated Project
If you need to use KV storage capability or synchronize environment variables already set in the console to local debugging, you can execute the associate project command, enter the project name as required, where the project name here is the Pages project name already created in the preparation work.
edgeone pages link
6. Submitting Deployment
After local development and debugging, push the project code to the Git remote, and the CI build and deployment of the Pages backend will be triggered, completing the entire development process.
7. Local Deployment
If your project is created through "Direct Upload", you can first build and package the project locally, then deploy it directly to the Pages platform using the following command.
edgeone pages deploy <directoryOrZip> -n <projectName> [-e <env>]
Parameter Description
<directoryOrZip>: Required path of the folder or ZIP package to be deployed
-n, --name: Name of the project to be deployed. If the project does not exist, a new project will be created automatically (required).
-e, --env: Target deployment environment, available values: production or preview (default: production)
Local Deployment Example
# Production environment deploymentedgeone pages deploy ./dist -n project-name# Preview environment deploymentedgeone pages deploy ./ dist.zip -n project-name -e preview
Note:
The above command depends on edgeone login. You can also refer to the "CI pipeline example" to use an API Token for deployment.
8. Switching Accounts
If you need to switch to another Tencent Cloud account, you can execute the following commands and then log in again:
edgeone switch
CI/CD Pipeline Integration
You can also integrate EdgeOne CLI into the CI/CD pipeline to achieve automatic deployment.
Note:
The installation method of EdgeOne CLI can be found in the previous section "Quick Start - Installation".
CI Pipeline Deployment Command
deploy
command supports a Git-independent way to directly deploy folders or ZIP packages from CI/CD pipelines to EdgeOne Pages.edgeone pages deploy <directoryOrZip> -n <projectName> -t <token> [-e <env>]
Parameter Description
<directoryOrZip>: Required path of the folder or ZIP package to be deployed
-n, --name: Name of the project to be deployed. If the project does not exist, a new project will be created automatically (required).
-t, --token: API Token for CI/CD pipelines (required)
-e, --env: Target deployment environment, available values: production or preview (default: production)
CI Pipeline Example
# Production environment deploymentedgeone pages deploy ./dist -n project-name -t $EDGEONE_API_TOKEN# Preview environment deploymentedgeone pages deploy ./dist.zip -n project-name -e preview -t $EDGEONE_API_TOKEN
Getting Method for API Token
Before using the deployment command in the CI/CD pipeline, generate an API Token in the EdgeOne Pages console. For more information, see the API Token document.