头图

1. Project introduction

This project is written based on the scope of WeChat cloud hosting capabilities and builds a simple WEB back-end service, which counts the access logs of WEB web pages and saves them in a serverless mysql database, and then calls the service interface in the applet to obtain the number of visits.

The project includes the basic capabilities of WeChat cloud hosting in a single operation, including basic containers, mysql, WeChat applet calls, etc.

Project technology stack: back-end service (nodejs + express), WEB page (native js), WeChat applet (native)

If you have experienced the basic capabilities of WeChat Cloud hosting, you can continue to experience the related use of WeChat Cloud hosting in other Tencent Cloud products, log monitoring and other capabilities.

Second, the deployment process

(1) Visit github warehouse , download the project locally, open the IDE and prepare to transform the project

(2) Visit the WeChat cloud hosting official website , use WeChat to scan the code, select the mini program you want to use, and enter the link to start creating.

(3) The environment name here can be filled in according to your own purpose. Generally, you can just create an environment for small program projects. An environment can contain multiple services, which can meet most of the enterprise-level needs.

(4) If you have used cloud development in the Mini Program before, and have logged in to the Tencent Cloud official website to configure other Tencent Cloud cloud products, for ease of use, you can select a private network in the "Network Type" in the creation box to set the cloud hosting environment Configure to the same network environment as before (if you don’t want to do this or you haven’t done anything, just create it by default)

(5) Clearly know the cost of the cloud hosting environment, agree to the terms of service, and start the creation.

(6) After the creation is successful, the following effects will be displayed:

(7) Start to create the mysql database, as shown in the following figure:

(8) After filling in the password, mysql is being initialized, please pay attention to the cost information here, as shown in the figure below after initialization:

(9) Click the "Database Management" button in the upper right corner to enter the database management background and start to create a library, as shown in the figure below, where the library name is online (the name is arbitrary, if you change it, please note that the operation will be changed accordingly)

(10) Import the database.sql file in the project directory into the online library, the effect is as follows:

(11) Return to the WeChat Cloud Hosting Console, add an account in the mysql column, dedicated to programming calls, as shown in the following figure:

(12) In the directory werunserver/db.json, fill in the mysql database information, where the host and port information are in the console

{
  "host": "10.0.224.13",//上图中的冒号之前ip地址
  "user": "code",       //上一步设置的账户名称
  "password": "*****",  //上一步设置的密码
  "port": "3306",       //上图中的冒号之后数字
  "database": "online"  //之前创建的数据库 online
}

(13) Save the project, use the project directory werunserver as the root directory, and upload the private git repository. Here, github is used as an example. [Note that werunserver must be the root directory

(14) In the WeChat Cloud Hosting Console, in the service column, select New Service, as shown in the figure below, remember to check Open public network access, and set the name at will (aaa in the example here)

(15) After the creation is complete, enter the service management, as shown in the figure below, select the new pipeline

(16) The new pipeline configuration is as follows, the code source needs to be authorized the first time it is used:

(17) After the creation is completed, as shown in the figure below, click to start the first build:

(18) After the build is completed, the status is as follows, at this time we can start the release link

(19) Go to "Deployment and Release" to start the full release process

(20) The post-release effect is as follows:

(21) Return to the service list, find the public network address in the service details, and copy it to the browser to open:

(22) Since the configuration is low-cost mode, there is a container loading process for the first visit, and you can wait patiently (the request failure box will appear for about tens of seconds during the continuous refresh process, and the normal configuration of the network will not hurt.) The effect after the successful visit As follows, every refresh will have a record:

(23) Start the test of the WeChat applet, use the miniprogram in the project as the applet root directory and open it with the WeChat developer tool, fill in the first step to create the same applet APPID with the same service

(24) Open the pages/index/index.js file in the Mini Program Developer Tool and fill in the following information:

(25) Re-run and you're done!

3. Project summary

After this deployment, you can continue to make modifications based on this project, and re-push the updated code to the warehouse, and the pipeline will automatically trigger the build.

Before the new version is released, full testing can be carried out. Cloud hosting provides various test whitelist configurations; after testing and verification, it can be released in grayscale, and finally 100% of the new version can be ordered to complete the full replacement of the new version; if it is troublesome, Believe in your own ability, you can publish it in full, and have a great time!

In the future, more functions such as custom domain names will be supported in the console. You are still on the way, remember to check for updates frequently.

immediately experience WeChat cloud hosting: https://cloud.weixin.qq.com/cloudrun/

WeChat Cloud Hosting Official Community

For comments, suggestions and questions in the process of using WeChat cloud hosting, welcome to the official community to communicate with us: https://developers.weixin.qq.com/community/minihome/mixflow/1919566493118201863

cloud hosting official exchange group


CloudBase云开发
425 声望438 粉丝

云开发(Tencent CloudBase,TCB)是云端一体化的后端云服务 ,采用 serverless 架构,免去了移动应用构建中繁琐的服务器搭建和运维。同时云开发提供的静态托管、命令行工具(CLI)、Flutter SDK 等能力极大的降...


引用和评论

0 条评论