failed on using npm lazy from an external machine
Closed this issue · 5 comments
I use npm lazy through docker image with the following options:
root@jenkins:~# sudo docker run -p 8000:8080 -v /root/.npm_lazy langrisha/npm-lazy --show-config
{ loggingOpts:
{ logToConsole: true,
logToFile: false,
filename: '/root/npm_lazy.log' },
cacheDirectory: '/root/.npm_lazy',
cacheAge: 0,
httpTimeout: 10000,
maxRetries: 5,
rejectUnauthorized: true,
externalUrl: 'http://localhost:8080',
remoteUrl: 'https://registry.npmjs.org/',
port: 8080,
host: '0.0.0.0',
proxy: { https: undefined, http: undefined } }
when I try to fetch a package it gives error on "fetch failed http://localhost:8080",where as the option above shows "remoteUrl: 'https://registry.npmjs.org/'"
➜ ~ npm --registry http://192.168.1.122:8000/ install -g node-inspector
npm ERR! fetch failed http://localhost:8080/node-inspector/-/node-inspector-0.10.1.tgz
npm WARN retry will retry, error on last attempt: Error: fetch failed with status code 404
The server says it is fetching from the registry.npmjs.org.
app debug Querying the registry (not cached): https://registry.npmjs.org/
app debug [GET] https://registry.npmjs.org/node-inspector
I tried booting with the external-url option as the server url, and it gives the same error:
^Croot@jenkins:~# sudo docker run -p 8000:8080 -v /root/.npm_lazy langrisha/npm-lazy external-url http://192.168.1.122:8000/ --show-config
{ loggingOpts:
{ logToConsole: true,
logToFile: false,
filename: '/root/npm_lazy.log' },
cacheDirectory: '/root/.npm_lazy',
cacheAge: 0,
httpTimeout: 10000,
maxRetries: 5,
rejectUnauthorized: true,
externalUrl: 'http://192.168.1.122:8000/',
remoteUrl: 'https://registry.npmjs.org/',
port: 8080,
host: '0.0.0.0',
proxy: { https: undefined, http: undefined } }
wget on the server works:
➜ ~ wget 192.168.1.122:8000
➜ ~ more index.html
{"db_name":"registry","doc_count":163408,"doc_del_count":366,"update_seq":323655,"purge_seq":0,"compact_running":false,"
disk_size":701517947,"data_size":585819402,"instance_start_time":"1426808985434529","disk_format_version":6,"committed_u
pdate_seq":323655}
My npm config:
➜ ~ npm config get
; cli configs
user-agent = "npm/2.5.1 node/v0.12.1 linux x64"
; userconfig /home/jenkins/.npmrc
registry = "http://192.168.1.122:8000/"
Thanks for getting in touch and including all the necessary information - my guess would be that you need to run npm cache clean
on that host, because:
➜ ~ npm --registry http://192.168.1.122:8000/ install -g node-inspector
npm ERR! fetch failed http://localhost:8080/node-inspector/-/node-inspector-0.10.1.tgz
The fetch seems to go to http://localhost:8080/
, not http://192.168.1.122:8000/
. This can happen because the npm client does its own caching and the proxy works by rewriting the remoteUrl in the metadata returned from the registry with it's own external URL; an old cached metadata file may be causing the npm client to attempt to go to the wrong host.
Hi mixu,
Thanks for the fast response. Your suggestion worked on one of the machines running npm 1.4.8.
But it fails with a different error on a newer npm (2.5.1 version) with 406 response:
➜ ~ npm install npm -g --ca=null
npm ERR! fetch failed http://192.168.1.122:8000//npm/-/npm-2.11.0.tgz
npm WARN retry will retry, error on last attempt: Error: fetch failed with status code 406
npm ERR! fetch failed http://192.168.1.122:8000//npm/-/npm-2.11.0.tgz
npm WARN retry will retry, error on last attempt: Error: fetch failed with status code 406
^C
➜ ~ npm -v
2.5.1
I searched it and I believe that npm might have changed the accept header at that version: npm/npm#7174
I'm having the same problem.
I'm running npm_lazy in a server for my team. I run it with:
bash -c "nohup npm_lazy --config ~/npm_lazy.config.js > /dev/null 2>&1 &"
The config is like:
{
loggingOpts: {
logRequesterIP: true,
logToConsole: true,
logToFile: false,
filename: homePath + '/npm_lazy.log'
},
cacheDirectory: homePath + '/.npm_lazy',
httpTimeout: 10000,
maxRetries: 5,
rejectUnauthorized: true,
cacheAge: 24 * 60 * 60 * 1000,
externalUrl: 'http://localhost:5080',
remoteUrl: 'https://registry.npmjs.com/',
port: 5080,
host: '0.0.0.0',
proxy: {}
};
In my machine I run:
npm --registry http://myhost:5080/ install
My server setup is:
Node: v5.2.0
npm: 3.3.12
My local setup is:
Node: v5.3.0
npm: 3.8.1
@rafaeleyng I think you need to change the externalUrl
to be the IP address of the server or a URL - externalUrl
is sent to the clients so it should be something other than localhost
if you want other clients to be able to find the server
Hmmm, that was nice. I will try it ASAP.
Could you elaborate a little more on where does the client would use externalUrl
, since the client is already pointing to the server when running npm --registry http://myhost:5080/ install