2.0.0 • Published 9 years ago

etcd-registry-router v2.0.0

Weekly downloads
41
License
-
Repository
github
Last release
9 years ago

etcd-registry-router

Route http requests to services registered in etcd-registry

npm install etcd-registry-router

Usage

etcd-registry-router is a http server that forwards requests (and websockets!) to services registered in etcd-registry.

var router = require('etcd-registry-router');
var server = router('127.0.0.1:4001', function(request, route) {
	// pass a service name or service object to route the http request
	route(request.headers.host);
});

server.on('route', function(request, service) {
	console.log('Routing', request.url, 'to', service.name);
});

server.listen(8080);

The above snippet will start the router and route requests to services registered under {host-header}. To create a service that accepts all requests routed to example.com do.

var registry = require('etcd-registry');
var services = registry('127.0.0.1:4001');

var server = http.createServer(function(request, response) {
	response.end('hello from service')
});

server.listen(0, function() { // listening on 0 will just give you a free port
	services.join('example.com', {port:server.address().port});
});

See example.js for a working example.

License

MIT

2.0.0

9 years ago

1.2.1

9 years ago

1.2.0

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago

0.5.0

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago