How to password protect a nodejs application using the htaccess alternative

I have a site hosted in aws from www.domain.com with 2 subdomains test.domain.com and stage.domain.com. I use MEAN for development, now what I want to do is password protect my subdomains test.domain.com and stage.domain.com, but just like we do in php using htaccess.

Now I personally like this htaccess approach, because in this approach your code for the application will be the same, authentication will be added by htaccess. Any idea how to do this in nodejs without changing the application code so that I can remove this in the future if I want .

PS: Only hints are welcome.

+7
authentication .htaccess mean-stack
source share
1 answer

.htaccess does not modify the code because it is used by the Apache web server.

Keep in mind that Node.js is your web server, so wherever the magic happens (technically, adding basicAuth to node requires less code than adding htaccess to apache + to write the .htacess file).

Something, somewhere, should know that authentication needs to be done :).

Here's a link to an easy way to do this in node:

Basic HTTP authentication with node and Express 4

+8
source share

All Articles