|
|
const api = global.yoho.API;
|
|
|
const service = global.yoho.ServiceAPI;
|
|
|
const yohoApi = global.yoho.API;
|
|
|
const ufoAPI = global.yoho.UfoAPI;
|
|
|
const serviceApi = global.yoho.ServiceAPI;
|
|
|
const checkParams = require('../../utils/check-params');
|
|
|
const apiMaps = require('../../config/api-map');
|
|
|
|
|
|
const NOT_FOUND_API_MAP = {
|
|
|
code: 400,
|
|
|
message: '未找到对应的接口'
|
|
|
};
|
|
|
const checkApiMap = url => {
|
|
|
return apiMaps[url] ? apiMaps[url] : void 0;
|
|
|
};
|
...
|
...
|
@@ -15,7 +12,7 @@ const request = async({url, method, reqParams, context}) => { |
|
|
const {env, user} = context;
|
|
|
|
|
|
if (!apiInfo) {
|
|
|
return Promise.reject(NOT_FOUND_API_MAP);
|
|
|
return Promise.reject(new Error(`未找到对应的接口:${url}`));
|
|
|
}
|
|
|
if (!apiInfo.service) {
|
|
|
Object.assign(reqParams, {
|
...
|
...
|
@@ -32,26 +29,29 @@ const request = async({url, method, reqParams, context}) => { |
|
|
|
|
|
const params = checkParams.getParams(reqParams, apiInfo);
|
|
|
const cache = method.toLowerCase() !== 'get' ? false : apiInfo.cache;
|
|
|
const headers = {
|
|
|
'X-YOHO-IP': env.clientIp,
|
|
|
'X-Forwarded-For': env.clientIp,
|
|
|
'User-Agent': 'yoho/nodejs'
|
|
|
};
|
|
|
|
|
|
if (apiInfo.service) {
|
|
|
return await service.get(apiInfo.api, params, {
|
|
|
return await serviceApi.get(apiInfo.api, params, {
|
|
|
cache: cache,
|
|
|
code: 200,
|
|
|
headers
|
|
|
});
|
|
|
} else if (apiInfo.ufo) {
|
|
|
return await ufoAPI[method]('', params, {
|
|
|
cache: cache,
|
|
|
code: 200,
|
|
|
headers: {
|
|
|
'X-YOHO-IP': env.clientIp,
|
|
|
'X-Forwarded-For': env.clientIp,
|
|
|
'User-Agent': 'yoho/nodejs'
|
|
|
}
|
|
|
headers
|
|
|
});
|
|
|
} else {
|
|
|
return await api[method]('', params, {
|
|
|
return await yohoApi[method]('', params, {
|
|
|
code: 200,
|
|
|
cache: cache,
|
|
|
headers: {
|
|
|
'X-YOHO-IP': env.clientIp,
|
|
|
'X-Forwarded-For': env.clientIp,
|
|
|
'User-Agent': 'yoho/nodejs'
|
|
|
}
|
|
|
headers
|
|
|
});
|
|
|
}
|
|
|
};
|
...
|
...
|
|