mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-16 09:41:38 +08:00
Add user agent header
This commit is contained in:
@@ -7,10 +7,13 @@ let host = process.env.PUSHY_REGISTRY || 'https://update.reactnative.cn/api';
|
|||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
import request from 'request';
|
import request from 'request';
|
||||||
import ProgressBar from 'progress';
|
import ProgressBar from 'progress';
|
||||||
|
const packageJson = require('../package.json');
|
||||||
|
|
||||||
let session = undefined;
|
let session = undefined;
|
||||||
let savedSession = undefined;
|
let savedSession = undefined;
|
||||||
|
|
||||||
|
const userAgent = `react-native-update-cli/${packageJson.version}`;
|
||||||
|
|
||||||
exports.loadSession = async function() {
|
exports.loadSession = async function() {
|
||||||
if (fs.existsSync('.update')) {
|
if (fs.existsSync('.update')) {
|
||||||
try {
|
try {
|
||||||
@@ -68,6 +71,7 @@ function queryWithoutBody(method) {
|
|||||||
return query(host + api, {
|
return query(host + api, {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
|
'User-Agent': userAgent,
|
||||||
'X-AccessToken': session ? session.token : '',
|
'X-AccessToken': session ? session.token : '',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -79,6 +83,7 @@ function queryWithBody(method) {
|
|||||||
return query(host + api, {
|
return query(host + api, {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
|
'User-Agent': userAgent,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-AccessToken': session ? session.token : '',
|
'X-AccessToken': session ? session.token : '',
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user