--所需模块
安装模块 npm install bluebird logger
--所需模块
需求:在node中异步调用多个api返回数据处理
封装papi模块
/**
* api请求封装
*/
var request = require('request');
var Promise = require('bluebird');
var config = require('../config'); //配置文件
var logger = require('./logger')('console');
module.exports = {
// POST 请求封装
post : function(req, api, params, getMoreInfo, isUpload){
var formData = params || {};
formData.rS = config.rS;
if(typeof req.session.scsInfor !== 'undefined'){
formData.loginUid = req.session.loginUid;
formData.adUid = req.session.adUid;
}
var getMoreInfo = getMoreInfo || false;
var isUpload = isUpload || false;
if(req.session.token){
formData.token = formData.accessToken = req.session.token || '';
}
var baseUrl = config.server_base;
if(api.indexOf('http') >= 0){
baseUrl = "";
}
var reqConf = {
url : api,
baseUrl : baseUrl,
timeout : config.apiTime || 2000,
time : true,
method