0

I have multiple node.js apps running on my computer, and things are getting pretty confusing since the only difference between accessing them is the port number.

So I had the idea to use zeroconf to advertise them. I can now see my different apps in zeroconf capable browsers (Safari).

This is a great start, but not everybody on my team can use Safari, and so I'd like them to be accessible without port number.

So I'm looking for a way, to create redirects, or VirtualHost configs, based on zeroconf services. For example: if I have a zeroconf service called fileserver on machine some-server.local:3377, I'd like it to be accessible through http://fileserver.services.local, without port number.

Ideally it wouldn't redirect to http://some-server.local:3377, that's why I was thinking about VirtualHosts.

Is this feasible?

enyo
  • 121
  • 1
  • 5

1 Answers1

0

I'm not terribly familiar with zeroconf, but as I understand it, you don't have a config file as such - instead, each service will advertise itself. If this is correct, then I have a couple of suggestions.

The first is to use mod_rewrite and a RewriteMap. The RewriteMap will be a program that looks for the correct record and returns the informaton. Here's an example:

RewriteEngine On
RewriteMap zeroconf:/path/to/program
RewriteRule ^/(.*) http://${zeroconf:$HTTP_HOST}/$1 [P,L]

The program you're running as /path/to/program must take a hostname as argument (e.g. fileserver.services.local) and return the servername and port as some-server.local:3377. Mod_rewrite will then proxy that connection through to that server and port - if you don't want it proxied, remove the P from the RewriteRule.

Another way would be to use a RewriteMap that consists of a regular text file, and have a cron job running to discover any change in services and update that textfile every X minutes.

Writing the program to map hostname to hostname:port is left as an exercise to the reader...

Jenny D
  • 27,780
  • 21
  • 75
  • 114