hotfix.js
1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
*
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 16/8/22
*/
'use strict';
const http = require('http');
const logger = global.yoho.logger;
const env = process.env.NODE_ENV || 'development';
const hotfix = {
v1(req, res) {
let clientType = req.body.client_type || '';
let version = req.body.app_version || '';
let apiFile = `http://cdn.yoho.cn/app-hotfix2/${env}/yohobuy/`;
if (clientType.toLowerCase() === 'ios' && version) {
apiFile += `ios/${version}/api.json?_=` + (new Date()).getTime();
} else if (clientType.toLowerCase() === 'android' && version) {
apiFile += `android/${version}/api.json?_=` + (new Date()).getTime();
} else {
return res.json({
code: 400,
message: 'client_type or app_version error',
data: {}
});
}
http.get(apiFile, response => {
res.setHeader('Content-Type', 'application/json');
response.pipe(res);
}).on('error', err => {
logger.error('hot fix v1 error:', err);
return res.json({
code: 400,
message: 'read api file fail',
data: {}
});
});
}
};
module.exports = hotfix;