Development build of my Node.js site

I have a production build of my site on a VPS, and I deploy to a bare git repo which has a hook that checkouts the commits to an app directory. I use forever to keep my app running from the app directory.

What I want to do is set up a development build which I can push to. The development build could be hosted under a subdomain on my VPS. However, I'll need an authentication step that'll prevent anyone and everyone from accessing the development site. How could I put authentication in front of an entire site with little (if any) changes to my application?

Why don't you just run it on a port that isn't available to the public and then you could create an ssh tunnel and access it via localhost?

Add a dev ssh user to your VPS and assign it a password.

Your ssh tunnel would look like this (just adjust your ports accordingly):

ssh -N -L8808:localhost:8808 user@destination.com

You'll be prompted for your password and then you would leave your terminal session open and go to your dev server via "http://localhost:8808"

Another option (something I typically do). Is to have a file checked into your repo named "config.sample.json" with configuration information (in this case your username/password [development] restriction). Then you also set up git to ignore "config.json" (so you don't accidentally commit this to your repository and have to edit files on your production deployments).

Next you would write a function that would require that config.json file and use it's configuration data if the file is found otherwise it would load up as "production".

Then you would deploy your code to your development directory and afterward rename your "config.sample.json" to "config.json" and make any edits that were needed in that file to setup debugging, access control, etc.