Prerequisites: The NPM has been installed

Install code – push – the cli

The installation

If the code-push login IP:Host message is displayed, the Not found(404) page is displayed. The bugfix command is as follows

NPM install [email protected] - gCopy the code

Example for changing the admin password

$ curl -X PATCH -H "Authorization: Bearer mytoken" -H "Accept: application/json" -H "Content-Type:application/json" -d '{"oldPassword":"123456","newPassword":"654321"}' http://YOU_SERVICE_IP:3000/users/password
Copy the code

Code-push-server is deployed locally

Install the PM2

Introduction of PM2

PM2 is a node process management tool. It can be used to simplify many node application management tasks, such as performance monitoring, automatic restart, load balancing, and so on.

The following describes the PM2 and its common functions and configurations.

$ sudo npm i -g pm2
Copy the code

MYSQL installation

Refer to the link

  • Linux
  • macOS
  • Microsoft Windows
  • Others

Mysql8.x Default authentication caching_sha2_pasword is not supported in node-mysql2 see issue This will cause Node to fail to connect to the database

The solution

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourRootPassword'; -- or # CREATE a USER and set his authentication mode to mysql_native_password CREATE USER 'foo'@'%' IDENTIFIED WITH mysql_native_password BY 'bar';Copy the code

Installing code-push-server using source code (practice)

This exercise uses this method because it is easier to find the configuration file

$ git clone https://github.com/lisong/code-push-server.git
$ cd code-push-server
$ npm install
Copy the code

Install code-push-server globally using NPM

$ npm install code-push-server@latest -g
Copy the code

Initializing the database

Source code installation reference

$ ./bin/db init --dbhost "Mysql install IP" --dbport Mysql installed on port 3306  --dbuser "Username" --dbpassword "Password"
Copy the code

Global Installation Reference

$ code-push-server-db init --dbhost "Mysql install IP" --dbport Mysql installed on port 3306  --dbuser "Username" --dbpassword "Password"
Copy the code

Output: SUCCESS after success

Example Modify the configuration of code-push-server

Locate the config file in the config directory under the project directory and make the following changes:

  • local.storageDirCreate a storageDir directory and make sure it is readable and writable. Go to the directory and type PWD. Copy the path and paste it here
  • local.downloadUrl127.0.0.1Change it to the IP address of the machine you’re using.
  • common.dataDirCreate a dataDir directory and make sure it is readable and writable. Go to the directory and type PWD. Copy the path and paste it here
  • jwt.tokenSecretOpen the url to obtain the keyhttps://www.grc.com/passwords.htmAnd replaceINSERT_RANDOM_TOKEN_KEY.
  • dbSettings:username.password.host.portChange mysql to your own configuration

Configure pM2

Locate the process.json file in the docs directory under the project directory and make the following changes:

  • scriptIf the installation is global, set it tocode-push-serverIf it is source installation, use the path in the source code"Project path /bin/ WWW
  • CONFIG_FILEUse the absolute path to the config.js file

Start the code-push-server service

Execute commands in the docs folder

$ pm2 start process.json
Copy the code

Restart the code-push-server service

$ pm2 restart process.json
Copy the code

Disable the code-push-server service

$ pm2 stop process.json
Copy the code

The following figure shows the effect of successful startup

Check that the code-push-server service is running properly

YOUR_CODE_PUSH_SERVER_IP indicates the IP address of the code-push-server service

$ curl -I http://YOUR_CODE_PUSH_SERVER_IP:3000/
Copy the code

The result is as follows

return httpCode 200 OK

HTTP / 1.1 200 OK
X-DNS-Prefetch-Control: off
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=15552000; includeSubDomains
X-Download-Options: noopen
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Content-Type: text/html; charset=utf-8
Content-Length: 592
ETag: W/"250-IiCMcM1ZUFSswSYCU0KeFYFEMO8"
Date: Sat, 25 Aug 2018 15:45:46 GMT
Connection: keep-alive
Copy the code

Use Redis to improve concurrency and security

Configure redis in the config.js file

  • updateCheckCacheIf set to true, redis is used
  • rolloutClientUniqueIdCacheIf set to true, redis is used
  • tryLoginTimesIf set to true, redis is used

upgrade

NPM global installation mode

$ npm install -g code-push-server@latest
$ code-push-server-db upgrade --dbhost "your mysql host" --dbport "your mysql port"  --dbuser "your mysql user" --dbpassword "your mysql password" # upgrade codepush database
$ pm2 restart code-push-server # restart service
Copy the code

Source code installation

$ cd /path/to/code-push-server
$ git pull --rebase origin master
$ ./bin/db upgrade --dbhost "your mysql host" --dbport "your mysql port"  --dbuser "your mysql user" --dbpassword "your mysql password"
# upgrade codepush database
$ pm2 restart code-push-server # restart service
Copy the code

Check the pm2 log

$ pm2 ls
$ pm2 show code-push-server
$ tail -f "output file path"
Copy the code

Storage modes supported by code-push-server

  • local (default)
  • qiniu (qiniu)
  • s3 (aws)
  • oss (aliyun)
  • tencentcloud

Listen on Host/Port 0.0.0.0/3000 by default

This can be configured in process.json, env: PORT,HOST

Configure the React-Native project

See # React-Native Hot Update for configuration in Microsoft CodePush

Some commands will be slightly different because of the reduced code-push-CLI version

Create the Android project key

code-push app add MyRNAndroid android react-native
Copy the code

Create an iOS project key

code-push app add MyRNiOS ios react-native
Copy the code

Reference: github.com/lisong/code…