简体   繁体   English

通过浏览器从NPM获取软件包描述

[英]Getting package description from NPM via browser

I'm trying to write a Chrome Web App which will read information from NPM. 我正在尝试编写一个Chrome Web App,它将从NPM中读取信息。 Chrome obeys the Access-Control-Allow-Origin flags on websites, which is causing me some problems. Chrome遵循网站上的Access-Control-Allow-Origin标志,这给我带来了一些问题。

While I can read the following URL: 虽然我可以阅读以下网址:

http://registry.npmjs.org/simple-js/-/simple-js-0.1.5.tgz http://registry.npmjs.org/simple-js/-/simple-js-0.1.5.tgz

because it has access-control-allow-origin: * in the headers, I can't load this URL: 因为它在标头中具有access-control-allow-origin: * ,所以我无法加载此URL:

http://registry.npmjs.org/simple-js http://registry.npmjs.org/simple-js

Which is the one I need to actually find out what the latest version is (and hence find out the above URL). 我实际上需要找出最新版本的那个(从而找到上面的URL)。

Any ideas? 有任何想法吗? Is there a URL that I could access in order to find the same data? 是否可以访问一个URL以查找相同的数据?

Note: This is an app to read package info from NPM. 注意:这是一个从NPM中读取包装信息的应用程序。 I don't want to precompile NPM packages into it. 我不想将NPM软件包预编译到其中。

With Chrome Web Apps, you can set the manifest file to ignore the same-origin policy. 使用Chrome Web Apps,您可以将清单文件设置为忽略同源策略。 You can see this document: https://developer.chrome.com/extensions/xhr 您可以看到以下文档: https : //developer.chrome.com/extensions/xhr

That is the easiest solution I can think of. 这是我能想到的最简单的解决方案。 Alternatively, you may download the tgz file and decompress it on the client, or you can create a proxy to retrieve the JSON file (a web page that downloads the file and sends it back to the client with the appropriate headers). 或者,您可以下载tgz文件并在客户端上将其解压缩,或者可以创建代理以检索JSON文件(下载该文件并将其发送到具有适当标头的网页的网页)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM