I've used npm http-server a few times to broadcast my mac's filesystem over the LAN so I can access it via the different OS devices and their browsers in my home, instead of enabling file sharing in system preferences. I used the basic code, and connected successfully via localhost, and my ip address + port on other devices:
http-server [path to broadcast/serve] -p [random port] -o
I know this is not a good idea as anyone who can connect and guess the port can access my system, so I'm wondering if there is a way to password protect this connection. Can users be given an authentication prompt when trying to connect to [myip]:[port]? I tried fooling around with http-server's -S
-K
and -C
options, but couldn't figure out how to create these .pem files properly, or connect them to the server command.
I've also tried http-auth, and was able to create a prompt with the following code:
var http = require("http");
var auth = require("http-auth");
var basic = auth.basic({
file: __dirname + '/htpasswd'
});
http.createServer(basic, function(req, res) {
res.end('User successfully authenticated: ' + req.user);
}).listen(8080);
I know I'm new to this, but have been attempting to password protect this type of local network connection for about a week. Any ideas?