Published:
I get the following error using v0.0.3 of proxy-by-url from github:
19:55:27/seth/boltzman~/workspace/proxy-service-directory> node index.js
/home/seth/workspace/proxy-service-directory/node_modules/http-proxy/lib/http-proxy/index.js:119
throw err;
^
Error: Must provide a proper URL as target
at ProxyServer. (/home/seth/workspace/proxy-service-directory/node_modules/http-proxy/lib/http-proxy/index.js:68:35)
at Server.closure (/home/seth/workspace/proxy-service-directory/node_modules/http-proxy/lib/http-proxy/index.js:125:43)
at Server.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:527:27)
Using the example in the README.md
require('http-proxy').createServer(require('proxy-by-url')({
'/database': { port: 5984, host: 'localhost' },
})).listen(8000)
The problem comes from an API change to http-proxy. http-proxy v1.0 has a new API which is incompatible with proxy-by-url v0.0.3. So, I created a new module called proxy-by-directory that is inspired by proxy-by-url and works with http-proxy v1.0. It's on npm and github. You use proxy-by-directory like this:
var server = require('http').createServer(require('proxy-by-directory')({
'/articles' : { target : 'http://localhost:5555/' },
'/' : { target : 'http://sethlakowske.com:7777' }
})).listen(8000)