Authored by 陈峰

透传接口

... ... @@ -30,7 +30,7 @@ const plugin = {
// return Promise.reject();
},
initPurview(Vue, user) {
axios.defaults.headers.common.shopsId = user.currentShop.id;
Vue.$cookie.set('shopsId', user.currentShop.id);
return userService.purviews().then((purviews) => {
this.updateUser(Vue, user, purviews);
});
... ...
... ... @@ -26,8 +26,7 @@ let domainApis = {
exportSellerProductList: '/SellerProductController/exportSellerProductList',
updateSellerPrice: '/SellerPriceController/updateSellerPrice',
updateProduct: '/SellerProductController/updateProduct',
getProduct: '/SellerProductController/getProduct',
image2: '/SellerShopController/queryShopsByAdminPid',
getProduct: '/SellerProductController/getProduct'
}
};
... ...
const _ = require('lodash');
const Context = require('./context');
const request = require('request-promise');
const rp = require('request-promise');
const request = require('request');
const logger = global.yoho.logger;
const defaultOptions = {
resolveWithFullResponse: true
};
const API_INTERNAL_ERROR = {
code: 500,
... ... @@ -44,16 +44,35 @@ class Api extends Context {
headers: Object.assign(defaultHeader, headers)
});
}
download() {
proxy(url, data, options) {
let params = _.merge({
url,
headers: {
'Content-Type': 'application/json'
}
}, options);
if (options.method === 'get') {
params.qs = data;
} else {
params.body = JSON.stringify(data);
}
return request(params, (error, response) => {
if (!error) {
logger.info(`api call ${response.statusCode} [${response.request.method}] ${response.request.href} ${response.request.body}`); // eslint-disable-line
}
});
}
_request(options) {
options = Object.assign(options, defaultOptions);
return request[options.method || 'get'](options).then(response => {
options = Object.assign(options, {
resolveWithFullResponse: true
});
return rp[options.method || 'get'](options).then(response => {
let jsonBody = JSON.parse(response.body);
let req = response.request;
logger.info(`api call ${req.statusCode} [${req.method}] ${req.uri.href} ${req.body || ''}`);
logger.info(`api call ${response.statusCode} [${req.method}] ${req.uri.href} ${req.body || ''}`);
return jsonBody;
}).catch(err => {
logger.error(`api call ${err.statusCode} [${err.options.method}]
... ...
... ... @@ -2,6 +2,7 @@
const Context = require('../common/context');
const nodeExcel = require('excel-export');
// 暂时弃用
class OutputController extends Context {
constructor() {
super();
... ...
... ... @@ -42,7 +42,7 @@ module.exports = (req, res, next) => {
});
}
let userShops = req.user.shops;
let currentShop = _.find(userShops, shop => shop.id === req.get('shopsId'));
let currentShop = _.find(userShops, shop => shop.id === req.cookies.shopsId);
if (currentShop) {
let channel = apiMap.split('.')[0];
... ... @@ -56,14 +56,17 @@ module.exports = (req, res, next) => {
} else if (channel === 'platform') {
baseParams = {
shopsId: currentShop.shopsId,
shopId: currentShop.shopsId,
userId: req.session.LOGIN_UID
};
}
let params = Object.assign(req.query, req.body, baseParams);
return api[req.method.toLowerCase()](apiUrl, params).then(data => {
res.json(data);
}).catch(next);
return api.proxy(apiUrl, params, {
method: req.method.toLowerCase()
}).on('error', error => {
next({code: 500, message: error});
}).pipe(res);
}
return res.status(401).json({
code: 401,
... ...