提交 8352d42d088785cf0224b1c6651ba1fb230eafe5

作者 fanwh
1 个父辈 aecbfb50

no message

正在显示 1 个修改的文件 包含 49 行增加0 行删除
  1 +//RESTful API client 代理
  2 +
  3 +var http = require("http");
  4 +var uuid = require('uuid/v4');
  5 +var URL = require('url');
  6 +exports = module.exports = function (logger, settings) {
  7 + /*
  8 + * var options={
  9 + 'host': 'xxx.xxx.xxx.xxx',
  10 + 'port': 'xxxxx',
  11 + 'path': '/uaa/v1/xxxxx',
  12 + 'method': 'POST',
  13 + 'agent': false,
  14 + 'headers': {
  15 + "Accept": "application/json",
  16 + "Content-Type": "application/json",
  17 + 'User-Agent': 'Request for Express',
  18 + 'Authorization':"Bearer " + token
  19 + }
  20 + }
  21 + */
  22 +
  23 + var client = function (options, success, fail) {
  24 + return new Promise(function (resolve, reject) {
  25 + var postData = !options.params ? '' : options.params;
  26 + var httpRequest = http.request(options, function (res) {
  27 + var _data = '';
  28 + res.setEncoding('utf8');
  29 + res.on('data', function (chunk) {
  30 + _data += chunk;
  31 + });
  32 + res.on('end', function () {
  33 + resolve(_data, res);
  34 + });
  35 + });
  36 + httpRequest.on('error', function (e) {
  37 + reject(e);
  38 + });
  39 + httpRequest.write(postData);
  40 + httpRequest.end();
  41 + });
  42 + };
  43 +
  44 + return client;
  45 +};
  46 +
  47 +
  48 +exports['@singleton'] = true;
  49 +exports['@require'] = ['igloo/logger', 'igloo/settings'];
\ No newline at end of file
... ...
注册登录 后发表评论