Introduction to the

Scenario Describes how to quickly develop a Todo List based on the Cloud development platform, Midway FaaS, and RDS MySQL edition.

Background knowledge

Experience lab

Developers learn what and how of cloud computing through scenario-based experiments. Free cloud resources, real cloud environment, rich practice scenes

Address: developer.aliyun.com/adc/labs/

What is a cloud development platform?

The cloud development platform is a one-stop, all-cloud development platform provided by Ali Cloud. You can develop, debug and go online by opening a browser. Click on the cloud development platform.

What is Midway FaaS?

A Serverless framework for building Node.js cloud functions to help developers focus on product development and reduce maintenance costs.

Welcome to Star! Github.com/midwayjs/mi…

RDS database

Relational Database Service (RDS) is a stable, reliable, resilient and scalable online Database Service. It provides a full set of solutions for disaster recovery, backup, recovery, migration, and so on, completely solving the problems of Database operation and maintenance.

Create an

1. Log in to the cloud development platform. Open the website workbench.aliyun.com/, use ali Cloud account login,…

2. Create an application. Open quick StartWorkbench.aliyun.com/page/quicks…

3. Authorize cloud resource access. If you have not used the cloud development platform before, the option of cloud resource authorization management will appear. Scroll down and the word “agree to authorize” will appear. Click “Agree to authorize” and the authorization will be successful.Click Next after agreeing authorization and showing that authorization is successful.4. Create an application template. Select the development language NodeJS and create from the template. Click on the official template and select the Midway Serverless MySQL database sample application template, as shown.5. Set basic application information. Fill in the application name, application description, and computing service as shown in the figure. There are no products to choose from. Click next to the auto create product line and a Shanghai area product will appear. Click Next after filling in the information.6. Cloud service management. View the status of the cloud services that the application depends on. Right-click the unopened services and immediately open them. Open the page of all services on the new TAB and open them one by one as prompted. After the application card environment management is enabled, the application is created only when the small icon on the back of the application card environment management becomes a green check box.

The deployment of application

This section describes how to develop and deploy an application. 1. Enter development. After the application is created, the CloudIDE application details page is displayed. Click “Development Deployment” on the Application details page to enter the CloudIDE development page.2. Install dependencies. Click [Terminal], and then enter the following command NPM I in the terminal input box to install dependencies. There are a lot of packages involved in the dependency, it takes a little time to download all the packages, just wait patiently, after loading, you can see the hint in the following picture.

npm i 
Copy the code

3. Deploy. Click the Deployment TAB in CloudIDE, and then click Deploy to start deploying.4. Confirm the deployment information. In the dialog box that is displayed, the default database information is displayed. No configuration is required. If you need to configure your own database for a long time, follow the steps in Database Settings. Click Continue to deploy to enter the deployment phase.5. The daily environment is successfully deployed. After the daily environment is successfully deployed, the temporary domain name marked in the attachment can be used for access testing, as shown in the figure below.6. Temporary domain name access. You can access the Todo List Web application page by copying the generated temporary domain name. If the personal application needs to be sent online, bind the personal online domain name and continue to deploy it in the Online environmentThe Todolist Web application interface displays to-do items stored in database tables of the default configured database, as explained in the “Database Setup” section.

Offline application

  1. Function computing elastic instance related cloud resources have a certain amount of free, the amount of consumption will be paid according to the amount. If you do not need to reserve the application, click Offline on the application management page to avoid unnecessary costs.

Database Settings

The previous sections used the free default database provided in the app. There are two ways to configure the database: on the development platform and in CloudIDE, which are described below.

1. Set it on the cloud development platform.

A) In application details, click [Development and Deployment], and then click [Application Configuration] again to open the configuration page.

In application development, some sensitive information is usually used for data-related operations, such as database connection information, authentication information and so on. If this information is written directly into hardcode, there is a potential risk that sensitive information will be leaked as a result of code leaks. To reduce this risk, cloud development platforms recommend using “environment variables” instead of Hardcode’s approach.B) Modify environment variables. Because the default environment variables are set for this project, you can see the database connection information that has been created. You can modify the database connection information to your OWN RDS database from this screen, or you can create additional environment variables as you wish.Default environment variables:

MIDWAY_RDS_HOST RDS database connection address MIDWAY_RDS_PORT RDS database connection port MIDWAY_RDS_DBNAME RDS database name MIDWAY_RDS_USERNAME RDS database account name MIDWAY_RDS_PASSWORD Password of the RDS database account

2. Alternatively, you can change the database connection configuration directly in the code.

Start by looking at the database configuration file. Refer to the following attachment to view the database configuration file config.default.ts. The default database information is configured in the application program. If you want to develop your own application, you need to configure your own database information in this configuration file.3. The Todolist application’s to-do list is all read from the “Todo” table in the database, which is already created in the default database. If you have changed the database connection information to your own database, you need to execute the following table creation statement in your own database, which corresponds to the table creation statement:

CREATE TABLE `todo` (

 `id` bigint(20) NOT NULL AUTO_INCREMENT,

 `todo` varchar(255) NOT NULL,

 `status` int(11) NOT NULL,

 `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

 PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8
Copy the code