added wado uri proxy

This commit is contained in:
weiwei committed 2016-08-26 15:03:04 +08:00
1 parent a810aeceda
commit 0835c31ba0
8 files changed
+95 -15

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
Settings = Object.assign((Meteor.settings && Meteor.settings.proxy) ? Meteor.settings.proxy : {}, {
uri : "/__wado_proxy",
enabled: true
})
http = require("http");
url = require("url");
querystring = require("querystring");
+8
View File
@@ -0,0 +1,8 @@
WADOProxy = {};
WADOProxy.convertURL = function(wadoURL) {
if (!Settings.enabled) {
return wadoURL;
}
return Settings.uri + '?' + querystring.stringify({url: wadoURL});
}
+33
View File
@@ -0,0 +1,33 @@
Router.route(Settings.uri, function () {
let response = this.response;
if (!this.params.query.url) {
response.writeHead(500);
response.end('No wado url provided');
return;
}
let proxyRequest,
wadoUrl = url.parse(this.params.query.url, false);
var options = {
headers: {}
};
//options.headers = this.request.headers;
if (this.request.headers['referer']) {
options.headers.referer = this.request.headers['referer'];
}
if (this.request.headers['user-agent']) {
options.headers['user-agent'] = this.request.headers['user-agent'];
}
options.method = this.request.method;
options.host = wadoUrl.hostname;
options.port = wadoUrl.port ? wadoUrl.port : 80;
options.path = wadoUrl.path;
proxyRequest = http.request(options, function (proxyResponse) {
proxyResponse.pipe(response, {end: true});
});
//proxyRequest.end();
this.request.pipe(proxyRequest, {end: true});
}, {where: 'server'});