code-push-server Build your own push server process

github address: https://github.com/lisong/code-push-server

 

First, the server-side configuration process

1, Install and start code-push-server

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

$ cd code-push-server

$ npm install

 

2. Initialize the database

cd to the code-push-server directory

$ ./bin/db init --dbhost localhost --dbuser root --dbpassword #Initialize the mysql database

When initializing the database, this command does not have a password by default, please go to the code-push-server installation directory bin/db to modify



 

 

After the password is changed, the database initialization command can be executed successfully.

 

3. Modify the config.js configuration problem

Open configuration file



 Modify three places and create a new directory

 a, database configuration information, account password, etc.

 b, modify downloadUrl to the local ip address

  local: {

    // Binary files storage dir, Do not use tmpdir and it's public download dir.

    storageDir: "/Users/tablee/workspaces/storage",

    // Binary files download host address which Code Push Server listen to. the files storage in storageDir.

    downloadUrl: "http://192.168.0.7:3000/download",

    // public static download spacename.

    public: '/download'

  },

 c,  到https://www.grc.com/passwords.htm 这个地方,生成一个63 random alpha-numeric characters,填到tokenSecret字段里面

jwt: {

    // Recommended: 63 random alpha-numeric characters

    // Generate using: https://www.grc.com/passwords.htm

    tokenSecret: '6ix6a5Vw6knWnpZvlVhXqVGeQx86jGuaJb6YCdiVoyAbkA07IB59jgZKUcoizZI'

  },

 d,安装配置文件中的目录结构,到/Users目录中建立如下文件夹 /Users/tablee/workspaces/storage 

 

4,启动code-push-server服务器

cd到code-push-server目录,执行一下命令

$ ./bin/www #启动服务 浏览器中打开 http://127.0.0.1:3000 (也可以用本机ip访问 http://192.168.0.7:3000)

到此服务器端到配置就完成了。

 

二,客户端配置流程

客户端测试代码以 https://github.com/lisong/code-push-demo-app 为例

1,clone客户端代码

$ git clone [email protected]:lisong/code-push-demo-app.git

 

2, cd  到demo路径,执行npm install 安装node依赖包

 

3,用Android Studio打开code-push-demo-app/android目录

到MainApplication.java里面修改以下代码

@Override

protected List<ReactPackage> getPackages() {

  return Arrays.<ReactPackage>asList(

      new MainReactPackage(),

      new CodePush(

         "YourKey",  // code-push app add项目后生成的app 推送key

         MainApplication.this,

         BuildConfig.DEBUG,

         "YourCodePushServerUrl"   // config.js中配置的downloadUrl 地址 不需要/download后缀

      )

  );

}

下面是我的配置

@Override

    protected List<ReactPackage> getPackages() {

      return Arrays.<ReactPackage>asList(

          new MainReactPackage(),

          new CodePush(getResources().getString(R.string.reactNativeCodePush_androidDeploymentKey),

                  getApplicationContext(),

                  BuildConfig.DEBUG,

                  "http://192.168.0.7:3000/")

      );

    }

4,打开命令终端,登录code-push-server服务器,这里配置为local,所以登录地址为http://127.0.0.1:3000 或者 http://192.168.0.7:3000/

   $ code-push http://127.0.0.1:3000  //账号密码为博主提供  account:  admin password:  123456

登录成功之后获取token



 将文本框中的key复制粘贴到登录终端,点击回车登录成功

 

 5,添加推送app

$ code-push app add CodePushReactNativeDemo-android #android版

添加完成之后可以用code-push app list命令查看创建好的app,并将测试的Staging key拷贝到MainApplication.java中的 “Your Key“ 的位置,推送的时候通过key将app和服务器端关联

 

6,cd 到code-push-demo-app目录,允许react-native start 启动react-native 服务

 

7,Android Studio编译并将项目运行到手机上,reload更新到最新js包

 

8,在code-push-demo-app中首页随意做一些修改,这里添加了一段静态问题:“我是热更新内容" ,执行推送命令

测试环境执行:

$ code-push release-react CodePushReactNativeDemo-android android

生产环境执行:

$ code-push release-react CodePushReactNativeDemo-android android -d Production



 

9,到app中点击 “Start Sync!“ 执行完安装后,可以看到页面上多了“我是热更新内容". 



 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326356955&siteId=291194637