mixu/npm_lazy

adding support of hosting https mirror?

eidng8 opened this issue · 1 comments

This is a great tool, thanks for the good work!

Currently it only supports hosting http mirror, it would be great to have https: too.

I'm not familiar with nodejs, I mostly write web site codes. But it seems to me adding https: supports is easy as adding a few config values and code lines to

var server = http.createServer();

var server;
if(!!config.secure) {
  if(!config.server_key || !config.server_cert) {
    throw new Error('Please specify server certificates');
  }
  server = https.createServer({
    key: fs.readFileSync(config.server_key),
    cert: fs.readFileSync(config.server_cert)
  });
} else {
  server = http.createServer();
}

Is it?
server.on('request', function(req, res) {
  // snipped...
}).listen(config.port, config.host);

I was unable to get this work entirely.
First off, at the top of server.js I had to also add an https require require('https'),.
Also I changed the "externalUrl:" in the config file to be https instead of http.
After that, when I manually navigate to my proxy, I get valid files, and I can even download dependencies ,but neither npm nor yarn will actually install packages from it. I did change my registry URL in npm and yarn to the new https URL, and even cleared cache for both locally, but had no luck.

Let me know if you ever got this working.