tencent-express
component as an example to describe how to use Serverless Framework to develop, manage, deploy, and publish a project. You can see the demo here.Branch Type | Description |
master | It is used to deploy a production environment |
testing | It is used for testing in a testing environment |
dev | It is used for daily development |
feature-xxx | It is used to add a new feature; for example, different developers can pull different feature branches from dev for development |
hotfix-xxx | It is used to fix an urgent bug |
#serverless.ymlapp: expressDemoApp # Application name, which is the component instance name by defaultstage: ${env:STAGE} # Parameter used to isolate the development environment, which is `dev` by defaultcomponent: express # Name of the imported component, which is required. The `express-tencent` component is used in this examplename: expressDemo # Name of the instance created by the component, which is requiredinputs:src:src: ./exclude:- .envregion: ap-guangzhouruntime: Nodejs10.15functionName: ${name}-${stage}-${app} # Function nameapigatewayConf:protocols:- http- httpsenvironment: release
TENCENT_SECRET_ID=xxxxxxxxxx # `SecretId` of your accountTENCENT_SECRET_KEY=xxxxxxxx # `SecretKey` of your accountSTAGE=prod # `STAGE` is the `prod` environment. You can also run `sls deploy --stage prod` to pass in the parameter
sls deploy
succeeds, access the generated URL as shown below:
master
branch, and create testing
and dev
branches. In this way, the code of the three branches is on the same version (suppose it is v0).
feature1
and feature2
feature branches from dev
(v0) for development, respectively.
feature1
. In this example, a feature.html
file is added, and "This is a new feature 1." is written in it.sls.js
file:// Routesapp.get(`/feature`, (req, res) => {res.sendFile(path.join(__dirname, 'feature.html'))})
feature.html
:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Serverless Component - Express.js</title></head><body><h1>This is a new feature 1.</h1></body></html>
serverless.yml
as follows:TENCENT_SECRET_ID=xxxxxxxxxxTENCENT_SECRET_KEY=xxxxxxxxSTAGE=feature1
sls deploy
succeeds, the following content will be returned:region: ap-guangzhouapigw:serviceId: service-xxxxxxsubDomain: service-xxxxxx-123456789.gz.apigw.tencentcs.comenvironment: releaseurl: https://service-xxxxxx-123456789.gz.apigw.tencentcs.com/release/scf:functionName: express-demo-feature1runtime: Nodejs10.15namespace: defaultlastVersion: $LATESTtraffic: 1Full details: https://serverless.cloud.tencent.com/instances/expressDemoApp%3Afeature1%3AexpressDemo10s » expressDemo » Success
feature.html
file is added, and "This is a new feature 2." is written in it.dev
branch (conflicts may occur and need to be solved manually).
dev
. The .env file is configured as follows in the joint testing environment:TENCENT_SECRET_ID=xxxxxxxxxxTENCENT_SECRET_KEY=xxxxxxxxSTAGE=dev
sls deploy
to deploy the joint testing environment, access the URL (https://service-xxxxxx-123456789.gz.apigw.tencentcs.com/release/feature) as shown below:
dev
branch into testing
code to enter the testing stage.
TENCENT_SECRET_ID=xxxxxxxxxxTENCENT_SECRET_KEY=xxxxxxxxSTAGE=testing
sls deploy
succeeds, the testing personnel will carry out relevant tests until the features are stable in the testing.master
branch and prepare for release and launch.
TENCENT_SECRET_ID=xxxxxxxxxxTENCENT_SECRET_KEY=xxxxxxxxSTAGE=prod
sls deploy
serverless-express
project has been developed and published.
Was this page helpful?