Comparing version 0.5.4 to 0.6.0
@@ -20,1 +20,3 @@ /** | ||
module.exports.Middleware = require('./lib/middleware.js'); | ||
module.exports.RALPromise = require('./lib/promise.js'); |
@@ -19,2 +19,3 @@ /** | ||
var ctx = require('../../ctx.js'); | ||
var urlParse = require('url').parse; | ||
@@ -111,2 +112,14 @@ function HttpProtocolBase() { | ||
if (config.url) { | ||
var urlparsed = urlParse(config.url); | ||
if (urlparsed.protocol) { | ||
config.https = urlparsed.protocol === 'https:'; | ||
config.server = { | ||
host: urlparsed.hostname, | ||
port: parseInt(urlparsed.port, 10) | ||
}; | ||
config.server.port = config.server.port || (config.https ? 443 : 80); | ||
config.path = urlparsed.path; | ||
} | ||
} | ||
@@ -113,0 +126,0 @@ var opt = { |
@@ -10,12 +10,14 @@ /** | ||
var RAL = require('./ral.js'); | ||
var ral = require('./ral.js'); | ||
var ralP = require('./promise.js'); | ||
module.exports = function (options) { | ||
RAL.init(options); | ||
ral.init(options); | ||
return function (req, res, next) { | ||
req.RAL = RAL; | ||
req.RAL = ral; | ||
req.RALPromise = ralP; | ||
next(); | ||
}; | ||
}; |
{ | ||
"name": "node-ral", | ||
"version": "0.5.4", | ||
"version": "0.6.0", | ||
"description": "a rpc client for node", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -13,3 +13,2 @@ node-ral | ||
- [x] node 0.8.x | ||
- [x] node 0.10.x | ||
@@ -16,0 +15,0 @@ - [x] node 0.12.x |
@@ -30,2 +30,3 @@ /** | ||
req.RAL.should.be.ok; | ||
req.RALPromise.should.be.ok; | ||
config.getConf('FROM_MIDDLEWARE').should.be.ok; | ||
@@ -32,0 +33,0 @@ done(); |
@@ -16,2 +16,3 @@ /** | ||
var ral = require('../lib/ral.js'); | ||
var ralP = require('../lib/promise.js'); | ||
var path = require('path'); | ||
@@ -637,2 +638,82 @@ var server = require('./ral/server.js'); | ||
}); | ||
it('work fine with promise api', function (done) { | ||
before(function (ok) { | ||
isInited.on('done', ok); | ||
}); | ||
if (!global.Promise) { | ||
return done(); | ||
} | ||
ralP('POST_QS_SERV', { | ||
data: { | ||
msg: 'hi', | ||
name: '何方石' | ||
}, | ||
enableMock: false | ||
}).then(function (data) { | ||
servers.map(function (srv) { | ||
srv.close(); | ||
}); | ||
[8192, 8193].should.containEql(data.port); | ||
data.port.should.not.eql(8194); | ||
data.query.msg.should.eql('hi'); | ||
data.query.name.should.eql('何方石'); | ||
done(); | ||
}); | ||
}); | ||
it('work fine with promise api on error', function (done) { | ||
before(function (ok) { | ||
isInited.on('done', ok); | ||
}); | ||
if (!global.Promise) { | ||
return done(); | ||
} | ||
ralP('GET_QS_SERV', { | ||
path: '/close', | ||
timeout: 200, | ||
degrade: function (options) { | ||
throw new Error('degrade failed'); | ||
} | ||
}).catch(function (err) { | ||
err.toString().should.be.match(/degrade failed/); | ||
done(); | ||
}); | ||
}); | ||
it('work fine with http url request', function (done) { | ||
before(function (ok) { | ||
isInited.on('done', ok); | ||
}); | ||
ral('GET_QS_SERV', { | ||
url: 'https://www.baidu.com/search/error.html', | ||
unpack: 'string', | ||
timeout: 5000, | ||
rejectUnauthorized: false | ||
}).on('data', function (data) { | ||
data.should.match(/STATUS OK/); | ||
done(); | ||
}).on('error', function (err) { | ||
should.not.exist(err); | ||
done(); | ||
}); | ||
}); | ||
it('work fine with http url request', function (done) { | ||
before(function (ok) { | ||
isInited.on('done', ok); | ||
}); | ||
ral('GET_QS_SERV', { | ||
url: 'http://www.baidu.com/search/error.html', | ||
unpack: 'string', | ||
timeout: 5000, | ||
rejectUnauthorized: false | ||
}).on('data', function (data) { | ||
data.should.match(/STATUS OK/); | ||
done(); | ||
}).on('error', function (err) { | ||
should.not.exist(err); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -23,3 +23,3 @@ /** | ||
response.writeHead(503, { | ||
'Content-Type': 'text/plain' | ||
'Content-Type': 'text/plain', | ||
}); | ||
@@ -26,0 +26,0 @@ response.end(); |
326879
87
9543
152