Using http-proxy properly

1,216 views
Skip to first unread message

Lucas Schirm

unread,
Sep 27, 2015, 6:42:57 PM9/27/15
to nodejs
Hi everyone,

I'm new on nodejs and start trying to setup multiple domains on my litle server, (the http is all setup and working), but when i try http-proxy solution they return:

root@NodeCass:/dados# nodejs server.js

/dados/node_modules/http-proxy/lib/http-proxy/index.js:119
    throw err;
          ^
Error: Must provide a proper URL as target
    at ProxyServer.<anonymous> (/dados/node_modules/http-proxy/lib/http-proxy/index.js:68:35)
    at Server.closure (/dados/node_modules/http-proxy/lib/http-proxy/index.js:125:43)
    at Server.EventEmitter.emit (events.js:98:17)
    at HTTPParser.parser.onIncoming (http.js:2108:12)
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:121:23)
    at Socket.socket.ondata (http.js:1966:22)
    at TCP.onread (net.js:525:27)


The error message only appears on console when i try to access the http on listened port, my last try was:

var http = require('http')
, httpProxy = require('http-proxy');

httpProxy.createServer({
  hostnameOnly: true,
  router: {
  }
}).listen(80);


i've change my host file to this domain access this server, and works fine when i try to access it directly, like: http://ogenial.com.br:3001 but http-proxy keep saying its not a proper URL.

Thank in advance.

Att,
Lucas Schirm

Ryan Schmidt

unread,
Sep 28, 2015, 4:57:35 PM9/28/15
to nod...@googlegroups.com
The way you're trying to use http-proxy does not look like any of the ways described in their documentation:

https://www.npmjs.com/package/http-proxy

Have you tried to do it the way they show on that page?

Lucas Schirm

unread,
Sep 29, 2015, 11:08:36 AM9/29/15
to nod...@googlegroups.com
Hey,

This realy help me, the real problem was im trying to put http and httpProxy in diferent instances of nodejs, i thing he was able do listen the door on server and detect it open an responding, but to work, the httpProxy and http need to be start on same instance.

Thanks alot, and have a nice day, in future i will look at this site, great documentation, the GitHub was not so good as reference.

have a nice day!!!!


--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/9B952601-6693-4D56-9E4D-1244A9780AE1%40ryandesign.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages