Network access - use CORS proxy to access NPM registry
Closed this issue · 1 comments
webnpm needs some way to access the network if it ever hopes to be useful.
Use a CORS proxy https://www.npmjs.com/package/corsproxy? XMLHttpRequest, also see https://fetch.spec.whatwg.org
The failure (after fixes in GH-2) without a CORS proxy is:
npm.commands.install(['ucfirst'])
bundle.js:76 npm command require /node_modules/npm/lib/install.js
undefined
bundle.js:439 Refused to set unsafe header "accept-encoding"
bundle.js:439 Refused to set unsafe header "referer"
bundle.js:439 Refused to set unsafe header "user-agent"
bundle.js:93897 Uncaught TypeError: undefined is not a function
bundle.js:427 OPTIONS https://registry.npmjs.org/ucfirst
localhost/:1 XMLHttpRequest cannot load https://registry.npmjs.org/ucfirst. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9966' is therefore not allowed access. The response had HTTP status code 404.
with a CORS proxy (run sudo npm install -g corsproxy ; corsproxy
locally for now), running into more problems with browser-request:
req.on("error", cb)
req.on("socket", function (s) {
s.on("error", cb)
})
The returned req
is an XMLHttpRequest, and it is not an EventEmitter so it doesn't have the on
property (it does have onerror
, from the XHR spec). Missing compatibility in browser-request, which https://github.com/iriscouch/browser-request was last published a year ago (correction: 3 months, wrong repo in package.json? https://github.com/jhs/browser-request) , and has many open pull requests - no longer maintained? Either way, might be better to develop a more generic network request proxy (tunnel the requests over, e.g., web sockets) instead of request -> browser-request -> corsproxy