Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to password protect nodejs application using alternative to htaccess

I have a site hosted in aws with www.domain.com with 2 sub domains test.domain.com and stage.domain.com. I am using MEAN for development, now what i want is to password protected my sub domains test.domain.com and stage.domain.com but in a similar fashion as we do in php using htaccess.

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

P.S. : Only hints are welcomed.

like image 326
dipak1296 Avatar asked Oct 14 '14 09:10

dipak1296


1 Answers

.htaccess does not alter the code because it's used by the Apache webserver.

Consider that Node.js IS your webserver, so that's where the magic happens (technically, it takes less code to add basicAuth to node than to add htaccess to apache + write the .htacess file).

Something, somewhere has to know that authentication is to be done :).

Here's the link to an easy way to do that in node :

Basic HTTP authentication with Node and Express 4

like image 61
xShirase Avatar answered Sep 20 '22 13:09

xShirase