Make NodeJs App Private for Heroku

I'm trying to make the NodeJS application on Heroku private so that only developers can see it. Is there an easy way to do this, like basic auth? (All the solutions that I continue to search for are specific to Ruby applications.)

+6
source share
2 answers

If you want to use basic authentication, here are two options: http-auth and Passport . http-auth is a very simple module, and Passport is a powerful module with authentication alternatives. Both modules provide code examples, from basic code to Express Framework integration.

+2
source

I have the same problem. I managed to get one solution that may work for you, but is not suitable for me, as it interferes with the user login from angular -fullstack.

I just need a quick way to password protect the application so that only developers and interested parties can see it. https://www.npmjs.org/package/http-auth seems to do the trick.

This is due to adding http-auth to your project (npm install http-auth --save). Then you need to find the file that defines your createServer, and the code there.

If you use Express, you can do something like this

// HTTP Authentication var preAuth = require('http-auth'); var basic = preAuth.basic({ realm: "Restricted Access! Please login to proceed" }, function (username, password, callback) { callback( (username === "user" && password === "password")); } ); // Setup server var app = express(); app.use(preAuth.connect(basic)); var server = require('http').createServer(app); 

If not, you can try one of the options from the http-auth documentation, for example.

 // Authentication module. var auth = require('http-auth'); var basic = auth.basic({ realm: "Simon Area." }, function (username, password, callback) { // Custom authentication method. callback(username === "Tina" && password === "Bullock"); } ); // Creating new HTTP server. http.createServer(basic, function(req, res) { res.end("Welcome to private area - " + req.user + "!"); }).listen(1337); 

There are also a couple of related threads here with somewhat similar approaches.

express.basicAuth expression error

Basic HTTP authentication in Node.JS?

0
source

Source: https://habr.com/ru/post/950210/


All Articles