16

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.

dipak1296
  • 349
  • 2
  • 3
  • 16
  • I don't think the step-by-step PHP approach has much to do with your question about Node.js, you should remove it, it'd make the question clearer – xShirase Oct 14 '14 at 09:52
  • possible duplicate of [Basic HTTP authentication with Node and Express 4](http://stackoverflow.com/questions/23616371/basic-http-authentication-with-node-and-express-4) – xShirase Oct 14 '14 at 09:55
  • And it's a duplicate, your answers are here : http://stackoverflow.com/questions/23616371/basic-http-authentication-with-node-and-express-4 – xShirase Oct 14 '14 at 09:56
  • @xShirase : agree removed that php code. your solution provides approach with express.basicAuth so for that i have to alter application current code, while htaccess don't alter application code. htaccess is just a external file. i wonder whether any such trick exist or not? – dipak1296 Oct 14 '14 at 10:15

1 Answers1

15

.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

Community
  • 1
  • 1
xShirase
  • 11,975
  • 4
  • 53
  • 85