Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network access - use CORS proxy to access NPM registry #1

Closed
deathcap opened this issue Feb 9, 2015 · 1 comment
Closed

Network access - use CORS proxy to access NPM registry #1

deathcap opened this issue Feb 9, 2015 · 1 comment

Comments

@deathcap
Copy link
Owner

deathcap commented Feb 9, 2015

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

deathcap added a commit that referenced this issue Feb 9, 2015
npm-registry-client is another module with dynamic require. Add
preloaded fs.readdirSync() with the directory contents, and replace
the dynamic require() with our own. Ref GH-2, GH-1.
deathcap added a commit that referenced this issue Feb 9, 2015
webnpm now attempts to send the HTTP request. However, it fails due to
cross-origin restrictions. Now to proceed further needs:
GH-1 Network access
@deathcap
Copy link
Owner Author

deathcap commented Feb 9, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant