小编wha*_*dar的帖子

当http:// localhost是起源时致命的CORS

即使我使用适当的头设置服务器(nginx/node.js),我仍然遇到这个CORS问题.

我可以在Chrome网络窗格中看到 - >响应标题:

Access-Control-Allow-Origin:http://localhost
Run Code Online (Sandbox Code Playgroud)

应该做的伎俩.

这是我现在用来测试的代码:

var xhr = new XMLHttpRequest();
xhr.onload = function() {
   console.log('xhr loaded');
};
xhr.open('GET', 'http://stackoverflow.com/');
xhr.send();
Run Code Online (Sandbox Code Playgroud)

我明白了

XMLHttpRequest cannot load http://stackoverflow.com/. Origin http://localhost is not allowed by Access-Control-Allow-Origin.
Run Code Online (Sandbox Code Playgroud)

我怀疑它是客户端脚本中的问题而不是服务器配置...

javascript html5 xmlhttprequest cors xmlhttprequest-level2

150
推荐指数
9
解决办法
24万
查看次数

输出已安装的node.js库的所有许可证

在npm(或其他工具)中是否有选项可以打印所有使用过的许可证?我有一个项目,我想确保我不使用我无法使用的许可证库.

编辑:发现许多开发人员没有在package.json中包含许可证,所以我必须手动找到"npm docs package-name"

node.js npm

49
推荐指数
5
解决办法
2万
查看次数

使用uglifyjs对嵌套的类和变量进行管理

我使用uglifyjs来缩小连接的文件集,这种方法很好但不够好.构建的lib使用名称空间,因此类,函数和常量存储在根名称空间变量中:

(function() {
  var root = { api:{}, core:{}, names:{} };

  /* util.js file */
  root.names.SOME_LONG_NAMED_CONST='Angel';

  /* Person.js file */
  root.core.Person = function(name) { this.name = name };

  /* API.js with the functions we want to expose */
  root.api.perform = function(param_for_api) { /* do something */ }

  window.lib_name.perform = root.api.perform;

})();
Run Code Online (Sandbox Code Playgroud)

这被缩小为不那么小的版本

(function(){var a={api:{},core:{},names:{}};a.names.SOME_LONG_NAMED_CONST="Angel",a.core.Person=function(a){this.name=a},a.api.perform=function(){},window.lib_name.perform=a.api.perform})();
Run Code Online (Sandbox Code Playgroud)

我理解uglify可能认为root var是一个必须按原样保存并且不能更改的数据结构.有没有办法让uglify破坏根命名空间中的嵌套名称?

javascript minify uglifyjs uglifyjs2

7
推荐指数
2
解决办法
6077
查看次数

拒绝获得不安全的标题"Content-Range"

由于某种原因,我无法再访问"Content-Range"的响应头...因此,使用XHR无法确定资源的文件大小.我Refused to get unsafe header "Content-Range"在此行中遇到Chrome 错误:

var cr = this.getResponseHeader('Content-Range');
Run Code Online (Sandbox Code Playgroud)

这是CORS配置:

<?xml version="1.0" ?>
<CorsConfig>
<Cors>
    <Origins>
        <Origin>*</Origin>
    </Origins>
    <Methods>
        <Method>GET</Method>
        <Method>HEAD</Method>
        <Method>DELETE</Method>
    </Methods>
    <ResponseHeaders>
        <ResponseHeader>x-goog-meta-foo1</ResponseHeader>
        <ResponseHeader>origin</ResponseHeader>
        <ResponseHeader>range</ResponseHeader>
        <ResponseHeader>Content-Range</ResponseHeader>
        <ResponseHeader>Content-Length</ResponseHeader>
    </ResponseHeaders>
    <MaxAgeSec>1800</MaxAgeSec>
</Cors>
Run Code Online (Sandbox Code Playgroud)

CURL输出:

$ curl -H "Origin: http://peer5.com" http://commondatastorage.googleapis.com/peer5_vod/wind2_orig.mp4 -s -D - -o /dev/null
HTTP/1.1 200 OK
Server: HTTP Upload Server Built on May 8 2013 16:51:19 (1368057079)
Expires: Mon, 13 May 2013 09:47:40 GMT
Date: Mon, 13 May 2013 08:47:40 GMT
Cache-Control: public, max-age=3600, no-transform …
Run Code Online (Sandbox Code Playgroud)

xmlhttprequest http-headers google-cloud-storage

2
推荐指数
1
解决办法
8943
查看次数