This is why the addition of basic auth is not... that basic. There is no real good solution using Node IMHO. It'd be easier done from outside the application, using a reverse proxy for instance.