React Native 热更新-搭建本地code-push-server

1.安装mysql (自行安装)

2.下载 code-push-server 仓库

git clone https://github.com/lisong/code-push-server.git

cd code-push-server && npm install

code-push-server推荐使用npm安装。

npm install code-push-server@latest -g

npm的方式需要安装pm2(PM2 是一个带有负载均衡功能的 Node 应用进程管理器。)

npm i -g pm2

3.修改 code-push-server config文件

源码位置:

 npm config.js文件路径:

/usr/local/lib/node_modules/code-push-server/config/config.js

windows默认为用户文件夹下

 C:UsersUserNameAppDataRoaming pm ode_modulescode-push-serverconfigconfig.js

 3.1 修改db中的数据库信息, 如下:

// Config for database, only support mysql.
  db: {
    username: process.env.RDS_USERNAME || "root",
    password: process.env.RDS_PASSWORD || "root",
    database: process.env.DATA_BASE || "codepush",
    host: process.env.RDS_HOST || "127.0.0.1",
    port: process.env.RDS_PORT || 3308,
    dialect: "mysql",
    logging: false,
    operatorsAliases: false,
  },
3.2 修改local对象的下载地址为本机(或服务器的ip地址)和StorageDir
// Config for local storage when storageType value is "local".
  local: {
    // Binary files storage dir, Do not use tmpdir and it's public download dir.
    storageDir: process.env.STORAGE_DIR || "D:/Publish/codePushStorage",//修改这里
    // Binary files download host address which Code Push Server listen to. the files storage in storageDir.
    downloadUrl: process.env.LOCAL_DOWNLOAD_URL || "http://222.111.1.77:3000/download",//修改这里
    // public static download spacename.
    public: '/download'
  },
 
3.3 修改jwt对象下的tokenSecret

打开 https://www.grc.com/passwords.htm, 复制其生成的随机字符串作为秘钥即可。

jwt: {
    // Recommended: 63 random alpha-numeric characters
    // Generate using: https://www.grc.com/passwords.htm
    tokenSecret: process.env.TOKEN_SECRET ||'dCJoA5FXuLN0VhsILzPsFqApYqHo4xWD1jjupTd1KQl8GiEaaLI8sJ0CTh5POrG'
  },
3.4  修改dataDir

根据local对象下的storageDir路径, 创建相应的文件夹。
创建common对象下的dataDir文件夹

common: {
    /*
     * tryLoginTimes is control login error times to avoid force attack.
     * if value is 0, no limit for login auth, it may not safe for account. when it's a number, it means you can
     * try that times today. but it need config redis server.
     */
    tryLoginTimes: 0,
    // CodePush Web(https://github.com/lisong/code-push-web) login address.
    //codePushWebUrl: "http://127.0.0.1:3001/login",
    // create patch updates's number. default value is 3
    diffNums: 3,
    // data dir for caclulate diff files. it's optimization.
    dataDir: process.env.DATA_DIR || "X:/codePushStorage",//修改这里
    // storageType which is your binary package files store. options value is ("local" | "qiniu" | "s3"| "oss" || "tencentcloud")
    storageType: process.env.STORAGE_TYPE || "local", //修改这里
// options value is (true | false), when it's true, it will cache updateCheck results in redis. updateCheckCache: false, // options value is (true | false), when it's true, it will cache rollout results in redis rolloutClientUniqueIdCache: false, },
4.初始化数据库信息
源码的方式:
./bin/db init --dbhost "your mysql host" --dbport "your mysql port"  --dbuser "your mysql user" --dbpassword "your mysql password"

npm的方式

code-push-server-db init --dbhost "your mysql host" --dbport "your mysql port"  --dbuser "your mysql user" --dbpassword "your mysql password"

5.启动服务

源码的方式:
npm start

npm的方式:这种方式没有pm2稳定

code-push-server

配置 pm2

保存文件 process.json到自己的文件夹如:X:filePathprocess.json

下面配置项必须修改:

  • script  npm安装值位 code-push-server,源码使用"源码目录"/bin/www
  • CONFIG_FILE  上面的config.js 路径,使用绝对路径.

START SERVICE

$ pm2 start X:filePathprocess.json

RESTART SERVICE

$ pm2 restart X:filePathprocess.json

STOP SERVICE

$ pm2 stop X:filePathprocess.json

CHECK SERVICE IS OK

$ curl -I http://YOUR_CODE_PUSH_SERVER_IP:3000/

return httpCode 200 OK

查看 pm2 logs

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

修改端口号

在 /bin/www 文件 修改下面 默认为 3000 修改为 3890

/**

Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3890');
log.debug('port ' + port);

UPGRADE 升级

from npm package

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

from source code

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

 

 
原文地址:https://www.cnblogs.com/flyxlee/p/14085444.html