Migrate applet from cloud development to self-built server

Original link: https://www.ixiqin.com/2022/08/22/the-small-program-from-cloud-development-migrated-to-build-server/

Cloud development has recently begun to see a large price adjustment, and has configured a default minimum consumption: 19.9 yuan; speaking, this is not much money, but many of my small programs are very small, but they can’t stop running. In the past, the pay-as-you-go model would be more friendly to small programs operated by Buddhist systems like me. But now this payment model is not very friendly to people like me who are not large in each applet, but have multiple applet. Since I can develop a standard backend, and I really don’t think it’s necessary, I’ll take the time to migrate from cloud development to self-built servers.

Evaluate revision effort

When I started to migrate, I first needed to evaluate the cost of the migration. I chose to use grep to query the workload of my changes. Execute the following command to determine which files I call the cloud development method in, and determine the specific workload

 grep -w -c -E 'callFunction|db.collection|wx.cloud' ./**/**.wpy

After executing the command, you will see output like this, which shows the amount of modification required for my specific file.

This will give you an idea of ​​the amount of work to be done. The next thing to do is nothing more than the specific migration work.

Evaluate cloud function workload

Cloud development has been used for a long time, and it is easy to appear some functions that are no longer working. In this case, you can no longer migrate these functions and reduce your own migration cost.

When migrating cloud functions, you can use the function monitoring interface provided by cloud development to determine the calling status of each function. For functions whose calling status is 0, you can selectively stop providing services.

export database

When migrating from cloud development, we need to migrate the code on the applet side, cloud function code and cloud database resources. Therefore, we also need to export and import the corresponding data.

However, what you need to pay attention to is that the JSON exported by cloud development is not in the standard JSON format, but in the format of JSON Lines . When you import the corresponding data, you need to use the package to parse it instead of using the standard way to parse it.

Modify the code

When the above things are done, the next thing to do is to write specific code to migrate, remember to migrate the code on both sides of the server & client~.

This article is reprinted from: https://www.ixiqin.com/2022/08/22/the-small-program-from-cloud-development-migrated-to-build-server/
This site is for inclusion only, and the copyright belongs to the original author.