-
Notifications
You must be signed in to change notification settings - Fork 2k
Error when running example #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
There has been an API change, and the examples do not yet reflect it. Passing a Sorry about the confusion - I'll try to get the docs updated ASAP. |
Same here. Example:
|
See my above comment - |
This is still a no-go for me.
server.js:
|
Does that help you at all? |
There indeed has been an API change which is more significant: if you were using the (function () {
"use strict";
var connect = require('connect')
, httpProxy = require('http-proxy')
, proxy
, server
;
function doProxy(req, res, next) {
proxy.proxyRequest(req, res, {
host: 'localhost'
, port: 3000
});
}
//
// Create a new instance of RoutingProxy to use in your server
//
proxy = new (httpProxy.RoutingProxy)();
server = connect.createServer(doProxy);
module.exports = server;
}()); Conversely, if you want to use the old (function () {
"use strict";
var connect = require('connect')
, httpProxy = require('http-proxy')
, proxy
, server
;
function doProxy(req, res, next) {
proxy.proxyRequest(req, res);
}
//
// Create a new instance of HttpProxy to use in your server
//
proxy = new (httpProxy.HttpProxy)({
target: {
host: 'localhost'
, port: 3000
}
});
server = connect.createServer(doProxy);
module.exports = server;
}()); What examples are broken? We can update them accordingly. |
Charlie, I think the READMe is out of date IIRC. |
I'm fixing the README and all the examples now. I'll publish the changes as soon as I'm sure all the examples work. |
Hmm, This is still not working for me. Documents are outdated or there is in fact a bug when using middleware. I get the following error: /node_modules/http-proxy/lib/node-http-proxy/routing-proxy.js:189
proxy.proxyRequest(req, res, options.buffer);
^
TypeError: Cannot call method 'proxyRequest' of undefined
at [object Object].proxyRequest (/Users/manuel/dev/clouddisplay/node_modules/http-proxy/lib/node-http-proxy/routing-proxy.js:189:9)
at Array.0 (/Users/manuel/dev/clouddisplay/proxy.js:71:22)
at Server.<anonymous> (/Users/manuel/dev/clouddisplay/node_modules/http-proxy/lib/node-http-proxy.js:173:39)
at Server.emit (events.js:67:17)
at HTTPParser.onIncoming (http.js:1131:12)
at HTTPParser.onHeadersComplete (http.js:108:31)
at Socket.ondata (http.js:1026:22)
at Socket._onReadable (net.js:683:27)
at IOWatcher.onReadable [as callback] (net.js:177:10) |
well, forget about the previous error. It was created by me when trying to fix the real problem I found. Namely that socket.io related requests do seem to use the new API while normal http request do not. For instance, I have a simple proxy created using: var proxyServer = httpProxy.createServer(myMiddleware) Now, inside my middleware I do this call: where dest is in the form {port:8081, host:'myhost'} This works well until socket.io tries to make a request, in that case I get the following error: Seems to me like there is some inconsistence with the APIs right now :/ |
@manast I need a bigger code sample to understand what you are referring to. If you are trying to proxy WebSockets, why are you not calling |
Hello, I will update with more code. But the reason I am not using proxyWebsocketRequest is because I did not need to do it before, and it worked well. Its after the API change that this has stop working. regards. On Sep 29, 2011, at 10:22 PM, Charlie Robbins wrote:
|
@manast I need a full code sample to give you any help. |
Ok, here it comes :) function matcher (url, dest) {
var r = new RegExp (url);
return function (url) {
var m = r(url);
if (!m) return
var path = url.slice(m[0].length);
logger.debug('URL match: ' + url + ' -> '+ path);
return {
url: path,
dest: dest
}
}
}
exports.urls = function (urls) {
var matchers = [];
for (var url in urls) {
matchers.push(matcher(url, urls[url]));
}
return function (req, res, next) {
var proxy = next;
for (var k=0; k<matchers.length;k++) {
var m
if (m = matchers[k](req.url)) {
req.url = m.url;
return proxy.proxyRequest(req, res, m.dest);
}
}
}
}
var proxyServer = httpProxy.createServer(
exports.urls({
'/api': {port: 8081, host: 'localhost'},
'/pubsub':{port: 8083, host: 'localhost'},
'/rekon': {port: 8098, host: 'localhost'},
'': {port: 3000, host: 'localhost'},
})
)
proxyServer.listen(80); |
any news on this issue? :) |
New version of |
The Proxy requests within another http server example (from README.md) raises the following error:
The text was updated successfully, but these errors were encountered: