我正在尝试创建自己的 local-npm 版本
我有这个简单的 http 服务器:
#!/usr/bin/env node
'use strict';
import http = require('http');
const s = http.createServer(function (clientRequest, clientResponse) {
if (clientRequest.url === 'x') {
clientResponse.write('retrieve the tarball from local fs');
clientResponse.end();
return;
}
const proxy = http.request({
hostname: 'https://registry.npmjs.org',
port: 80,
path: clientRequest.url,
method: clientRequest.method
},
function (res) {
res.pipe(clientResponse);
});
clientRequest.pipe(proxy);
});
s.listen(3441);
在本地终端中,我运行:
npm config set registry "localhost:3441"
只是为了踢我也运行这个:
npm set registry "localhost:3441"
并确认它有效,我这样做:
$(npm get registry) => "localhost:3441"
但是当我运行时npm install
,代理不会拦截任何内容,一切都只是转到 NPM。
我究竟做错了什么?