CodePush Server source
CodePush Server is a CodePush progam server! microsoft CodePush cloud is slow in China, we can use this to build our's. I use qiniu to store the files, because it's simple and quick! Or you can use local storage, just modify config.js file, it's simple configure.
- Apple allows the use of hot updatesApple's developer agreement, But the provisions can not be prompted to update the user box, affecting the user experience. And Google Play happens to be the opposite, you must inform the user to update. However, China's android market must close the update box, otherwise it will be in the audit application to "please upload the latest version of the binary application package" to reject the application.
- react-native Different platforms bundle packets are not the same, in the use of code-push-server must be created when the different applications to distinguish (eg. CodePushDemo-ios and CodePushDemo-android)
- React-native-code-push only update the resource file, will not update java and Objective C, so npm upgrade depends on the package version, if dependent on the use of localized package, this time must change the application version number (ios modify Info.plist CFBundleShortVersionString, Android modifies versionName in build.gradle) and then recompiles the app to the app store.
- It is recommended to use the code-push release-react command to publish the application, which combines the package and release commands (eg code-push release-react CodePushDemo-ios ios -d Production)
- Each time you submit a new version to the App Store, you should also publish an initial version to the code-push-server based on the submission. (Since each time a code-push-server is released, the code-puse-server compares with the initial version to generate the patch)
Api.code-push.com is just a test server, do not put their own production environment on the project, the server broadband only 1M, and the service did not do load balancing and monitoring, stability can not guarantee, please yourself build their own services.
$ code-push login http://api.code-push.com:8080 #Login访问:http://www.code-push.com:8080
$ npm install code-push-server -g
$ code-push-server-db init --dbhost localhost --dbuser root --dbpassword #Initialize the mysql database
$ code-push-server #Open the service in the browser http://127.0.0.1:3000$ git clone https://github.com/lisong/code-push-server.git
$ cd code-push-server
$ npm install
$ ./bin/db init --dbhost localhost --dbuser root --dbpassword #Initialize the mysql database
$ ./bin/www #Open the service in the browser http://127.0.0.1:3000from source code
$ cd /path/to/code-push-server
$ git pull --rebase origin master
$ ./bin/db upgrade --dbhost localhost --dbuser root --dbpassword #Upgrade the codepush database
$ #restart code-push-serverfrom npm package
$ code-push-server-db upgrade --dbhost localhost --dbuser root --dbpassword # Upgrade the codepush database
$ #restart code-push-server$ vim config/config.jsPlease check if the following configuration is consistent with your environment, especially the downloadUrl parameter
db: {
username: "root",
password: null,
database: "codepush",
host: "127.0.0.1",
dialect: "mysql"
},
//The storage cloud configuration configuration needs to be configured when storageType is qiniu
qiniu: {
accessKey: "",
secretKey: "",
bucketName: "",
downloadUrl: "" //File download domain name
},
//Ali cloud storage configuration needs to be configured when storageType is oss
oss: {
accessKeyId: "",
secretAccessKey: "",
endpoint: "",
bucketName: "",
prefix: "", // The prefix of the object Key is allowed to be placed inside the subfolder
downloadUrl: "", // File download domain name address, need to include prefix
},
//The file is stored locally and needs to be configured when storageType is local
local: {
storageDir: "/Users/tablee/workspaces/storage",
//File download address CodePush Server address + '/ download' download corresponding app.js inside the address
downloadUrl: "http://localhost:3000/download",
// public static download spacename.
public: '/download'
},
jwt: {
// Login jwt signature key, must be changed, otherwise there are security risks, you can use the randomly generated string
// Recommended: 63 random alpha-numeric characters
// Generate using: https://www.grc.com/passwords.htm
tokenSecret: 'INSERT_RANDOM_TOKEN_KEY'
},
common: {
dataDir: "/Users/tablee/workspaces/data",
//Select the storage type, currently supports local, oss, qiniu, s3 configuration
storageType: "local"
},
read config.js
- Configure local storage, modify config / config.js storageType value for the local, configuration in the following storageDir and downloadUrl local, if not on the same machine, downloadUrl Please specify the domain name or ip address
$ node ./bin/www # or code-push-serveror point config file and ENV
$ CONFIG_FILE=/path/to/config.js NODE_ENV=production node ./bin/www # or CONFIG_FILE=/path/to/config.js NODE_ENV=production code-push-servernotice. you have to change tokenSecret in config.js for security.
you can change like this.
$ PORT=3000 HOST=127.0.0.1 NODE_ENV=production node ./bin/www # or PORT=3000 HOST=127.0.0.1 NODE_ENV=production code-push-serverUse code-push-cli manager CodePushServer
$ npm install code-push-cli@latest -g
$ code-push login http://127.0.0.1:3000 #login in browser account:admin password:123456change admin password eg.
$ curl -X PATCH -H "Authorization: Bearer mytoken" -H "Accept: application/json" -H "Content-Type:application/json" -d '{"oldPassword":"123456","newPassword":"654321"}' http://127.0.0.1:3000/users/passwordreact-native-code-push for react-native
$ cd /path/to/project
$ npm install react-native-code-push@latest --saveFollow the react-native-code-push docs, addition iOS add a new entry named CodePushServerURL, whose value is the key of ourself CodePushServer URL. Andriod use the new CodePush constructor in MainApplication point CodePushServerUrl
iOS eg. in file Info.plist
...
<key>CodePushDeploymentKey</key>
<string>YourCodePushKey</string>
<key>CodePushServerURL</key>
<string>YourCodePushServerUrl</string>
...Android eg. in file MainApplication.java
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new CodePush(
"YourKey",
MainApplication.this,
BuildConfig.DEBUG,
"YourCodePushServerUrl"
)
);
}cordova-plugin-code-push for cordova
$ cd /path/to/project
$ cordova plugin add cordova-plugin-code-push@latest --saveedit config.xml. add code below.
<platform name="android">
<preference name="CodePushDeploymentKey" value="nVHPr6asLSusnWoLBNCSktk9FWbiqLF160UDg" />
<preference name="CodePushServerUrl" value="http://api.code-push.com:8080/" />
</platform>
<platform name="ios">
<preference name="CodePushDeploymentKey" value="Iw5DMZSIrCOS7hbLsY5tHAHNITFQqLF160UDg" />
<preference name="CodePushServerUrl" value="http://api.code-push.com:8080/" />
</platform>use pm2 to manage process.
$ npm install pm2 -g
$ cp config/config.js /path/to/production/config.js
$ vim /path/to/production/config.js #configure your env.
$ cp docs/process.json /path/to/production/process.json
$ vim /path/to/production/process.json #configure your env.
$ pm2 start /path/to/production/process.jsonUse CodePush Web manage apps
add codePushWebUrl config in ./config/config.js
eg.
...
"common": {
"codePushWebUrl": "Your CodePush Web address",
}
...MIT License read