The Koa component can help you quickly and conveniently create, configure, and manage a Koa framework in Tencent Cloud with the aid of the serverless-tencent basic components (such as API Gateway component and SCF component).
We recommend you use Node.js 10.0 or above; otherwise, Component v2 may report errors during deployment.
If your account is a Tencent Cloud sub-account, please get the authorization from the root account first as instructed in Account and Permission Configuration.
The following steps are mainly for deployment on the command line. For deployment in the console, please see Console Deployment Guide.
If you don't have a local Koa project, you can quickly create a Koa project template with the following command (if you already have one, you can ignore this step):
serverless init koa-starter --name example cd example
Open the entry file
app.js) of the Koa project, comment out the local listening port, and export the default Koa application:
// sls.js const koa = require('koa'); const app = koa(); // ***** // Comment out the local listening port // app.listen(3000); // Export the Koa application module.exports = app;
After modifying the code, you can run the
sls deploy command, and Serverless Framework will automatically generate a basic
serverless.yml file and complete the deployment to quickly migrate the Koa framework application.
The generated default configuration file is as follows:
component: koa name: koaDemo app: appDemo inputs: entryFile: sls.js # Use the actual entry file name src: ./ region: ap-guangzhou runtime: Nodejs10.15 apigatewayConf: protocols: - http - https environment: release
After the deployment is completed, access the application by accessing the output API Gateway link.
You can add more configuration items in
serverless.yml based on your actual deployment needs and run
sls deploy for redeployment.
For more information on the configuration of the .yml file, please see Koa Component Configuration.
After the deployment is completed, you can log in to the SSR console to view the basic information of the application and monitor logs.
Currently, you can scan a QR code to log in to the CLI by default. If you want to configure persistent environment variables/key information, you can also create a local
touch .env # Tencent Cloud configuration information
Configure Tencent Cloud's
SecretKey information in the
.env file and save it:
# .env TENCENT_SECRET_ID=123 TENCENT_SECRET_KEY=123
You can view more component information in the repository of Serverless Components.