code-push搭建

2020/03/09 React-Native

安装

  • code-push代码下载到本地:git clone https://github.com/lisong/code-push-server.git
  • cd code-push-server
  • npm install
  • 解决跨域访问:npm install cors
    • 在app.js中加入

    var cors = require('cors') app.use(cors()); ## 配置

  • 修改配置文件
  • cd config
  • vim config.js
  • 主要需要的修改部分如下,需配置mysql及文件存储路径 ``` config.development = { // Config for database, only support mysql. db: { username: process.env.RDS_USERNAME || “root”, password: process.env.RDS_PASSWORD || “123456”, database: process.env.DATA_BASE || “codepush”, host: process.env.RDS_HOST || “127.0.0.1”, port: process.env.RDS_PORT || 3306, dialect: “mysql”, logging: false, operatorsAliases: false, }, // 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 || “/home/codepush/storage”, // Binary files download host address which Code Push Server listen to. the files storage in storageDir. downloadUrl: process.env.LOCAL_DOWNLOAD_URL || “http://47.240.2.128:3000/download”, // public static download spacename. public: ‘/download’ }, jwt: { // Recommended: 63 random alpha-numeric characters // Generate using: https://www.grc.com/passwords.htm tokenSecret: process.env.TOKEN_SECRET ||’B4BDA53DEE90AD2AE2BC59C54CB54DA676DAB13F8EF7B258FC85EC8839E91FA0’ }, common: { codePushWebUrl:”http://127.0.0.1:3001”, // data dir for caclulate diff files. it’s optimization. dataDir: process.env.DATA_DIR || “/home/codepush/data”, }, }
- 初始化code-push-server的MySQL数据库:./bin/db init --dbhost "127.0.0.1" --dbport "3306"  --dbuser "root" --dbpassword "123456"
- 创建process.json配置文件

{ “apps” : [ { “name” : “code-push-server”, “max_memory_restart” : “300M”, “script” : “/www/code-push-server/bin/www”, “instances” : “max”, //开启实例数量,max为cpu核数 “exec_mode” : “cluster”, //集群模式,最大提升网站并发 “env” : { “NODE_ENV” : “production”, “PORT” : 3000, “CONFIG_FILE” : “/www/code-push-server/config/config.js” } } ] } ``` - 启动:pm2 start process.json - 通过ip:3000可以访问code-push管理端

更新code-push-server

  • git pull –rebase origin master
  • ./bin/db upgrade –dbhost “127.0.0.1” –dbport “3306” –dbuser “root” –dbpassword “123456”
  • pm2 restart code-push-server # restart service

参考资料

CodePush(搭建自己的推送服务) react-native-code-push进阶篇 CodePush热更新详细接入教程

Search

    Table of Contents