sails-upstream
v0.0.2
Published
upstream for sails framework
Downloads
4
Readme
sails-upstream
Convert sails request req
to stream, which can be used to pipe body (include file uploaded) to other request,
such as http-proxy
.
Install
$ npm install sails-upstream --save
Usage
Proxy request.
// api/policies/upstream.js
const httpProxy = require('http-proxy');
const {RequestStream} = require('sails-upstream');
const proxy = httpProxy.createProxyServer({});
module.exports = (req, res, next) {
proxy.web(req, res, {target: target, ws: true, buffer: new RequestStream(req)});
};
Upload file to buffer.
// api/controller/TestController.js
const httpProxy = require('http-proxy');
const {fileBuffer} = require('sails-upstream');
module.exports = {
async test(req, res){
const buffer = await fileBuffer(req.file('file'));
}
};