Factored out code that finds the closest URL to a resource given the EC2 instance the app is running on.

Added WS basic auth middleware.  Factored out later.