使用ember-cli-deploy的Ember.js部署错误

时间:2016-02-21 17:09:18

标签: ruby-on-rails ember.js amazon-s3 ember-cli

最终修改:感谢Luke Melia,我发现这是一个指纹识别问题。我需要将它的S3 URL添加到供应商文件之前。 These are the docs on it适用于将来遇到我的答案的任何人。

原始问题:

我已使用ember-cli-deploy Lightning Strategy部署了我的Ember应用。基本上,我不是将Ember资产移动到Rails public文件夹,而是将资产存储在S3上并使用Redis来获取内容。但是,我仍有问题。

修改:请查看下面的编辑内容。看起来它正在服务index.html而不是资产。也就是说,当我查看Chrome控制台中的“来源”标签并点击vendor-*.js文件时,它会显示index.html而不是正确的JavaScript文件。

控制台错误:

Failed to find a valid digest in the 'integrity' attribute for resource 'http://my-url.com/assets/vendor-d41d8cd98f00b204e9800998ecf8427e.css' with computed SHA-256 integrity 'jQneD+vBDVT7ee1Z9kI1izwIriOTtrL9BSbgXhWAyiY='. The resource has been blocked.
GET http://my-url.com/assets/vendor-810b00597803ee384ddec79fd82e6983.js ## These are 422 Unprocessable Entity errors.
GET http://my-url.com/assets/my-app-e62bc38bf7f8222ada28c3610ca3fc0c.js ## These are 422 Unprocessable Entity errors.
Failed to find a valid digest in the 'integrity' attribute for resource 'http://my-url.com/assets/my-app-d27a867b5c015e75b8e2110796a9e504.css' with computed SHA-256 integrity 'jQneD+vBDVT7ee1Z9kI1izwIriOTtrL9BSbgXhWAyiY='. The resource has been blocked.

我主要关注422错误,但我不确定为什么它仍会阻止CSS文件。 (修改:请参阅下面的编辑内容,了解我认为这种情况发生的原因。)

package.js依赖项:

"devDependencies": {
    "active-model-adapter": "2.1.1",
    "broccoli-asset-rev": "^2.2.0",
    "ember-ajax": "0.7.1",
    "ember-cli": "2.3.0",
    "ember-cli-app-version": "^1.0.0",
    "ember-cli-babel": "^5.1.5",
    "ember-cli-dependency-checker": "^1.2.0",
    "ember-cli-deploy": "0.5.1",
    "ember-cli-deploy-build": "0.1.1",
    "ember-cli-deploy-display-revisions": "0.1.1",
    "ember-cli-deploy-gzip": "0.1.1",
    "ember-cli-deploy-manifest": "0.1.1",
    "ember-cli-deploy-redis": "0.1.1",
    "ember-cli-deploy-revision-data": "0.1.1",
    "ember-cli-deploy-s3": "0.2.1",
    "ember-cli-deploy-ssh-tunnel": "0.2.2",
    "ember-cli-htmlbars": "^1.0.1",
    "ember-cli-htmlbars-inline-precompile": "^0.3.1",
    "ember-cli-inject-live-reload": "^1.3.1",
    "ember-cli-materialize": "git://github.com/robbyoconnor/ember-cli-materialize.git#e39b833f1dfb66b342873d25d05fabcb17b59a3f",
    "ember-cli-qunit": "^1.2.1",
    "ember-cli-release": "0.2.8",
    "ember-cli-sass": "5.2.1",
    "ember-cli-sri": "^2.0.0",
    "ember-cli-uglify": "^1.2.0",
    "ember-composability": "0.1.3",
    "ember-data": "^2.3.0",
    "ember-disable-proxy-controllers": "^1.0.1",
    "ember-export-application-global": "^1.0.4",
    "ember-key-responder": "0.4.2",
    "ember-legacy-views": "0.2.0",
    "ember-load-initializers": "^0.5.0",
    "ember-modal-dialog": "0.8.3",
    "ember-new-computed": "1.0.3",
    "ember-radio-button": "1.0.7",
    "ember-resolver": "^2.0.3",
    "loader.js": "^4.0.0"
}

我还尝试使用this SO answer中描述的ember-cli-cors,但这并没有什么不同。

配置/ environment.js:

module.exports = function(environment) {
  var ENV = {
    modulePrefix: 'my-app',
    environment: environment,
    baseURL: '/',
    locationType: 'auto',
    EmberENV: {
      FEATURES: {
      }
    },
    APP: {
    },
    contentSecurityPolicyHeader: 'Content-Security-Policy',
    contentSecurityPolicy: {
      'script-src': "'self' 'unsafe-eval' http://my-url.com",
      'style-src': "'self' 'unsafe-eval' http://my-url.com",
    }
  };

  return ENV;
};

S3上的CORS配置:

    <CORSConfiguration>
        <CORSRule>
            <AllowedOrigin>http://my-url.com/</AllowedOrigin>
            <AllowedMethod>GET</AllowedMethod>
            <MaxAgeSeconds>3000</MaxAgeSeconds>
            <AllowedHeader>*</AllowedHeader>
        </CORSRule>
    </CORSConfiguration>

编辑1:

我打开了有422个错误的文件,Rails production.log说:ActionController::InvalidCrossOriginRequest (Security warning: an embedded <script> tag on another site requested protected JavaScript.我最后将protect_from_forgery except: :index添加到我的前端控制器,现在这就是弹出的内容我的控制台:

控制台错误:

Failed to find a valid digest in the 'integrity' attribute for resource 'http://my-url.com/assets/vendor-d41d8cd98f00b204e9800998ecf8427e.css' with computed SHA-256 integrity 'rmy5bIbd1VtZvKFFNrowA8t7HzdFGJzV5tOFMqMQ8yE='. The resource has been blocked.
Failed to find a valid digest in the 'integrity' attribute for resource 'http://my-url.com/assets/vendor-810b00597803ee384ddec79fd82e6983.js' with computed SHA-256 integrity 'rmy5bIbd1VtZvKFFNrowA8t7HzdFGJzV5tOFMqMQ8yE='. The resource has been blocked.
Failed to find a valid digest in the 'integrity' attribute for resource 'http://my-url.com/assets/visual-climate-d27a867b5c015e75b8e2110796a9e504.css' with computed SHA-256 integrity 'rmy5bIbd1VtZvKFFNrowA8t7HzdFGJzV5tOFMqMQ8yE='. The resource has been blocked.
Failed to find a valid digest in the 'integrity' attribute for resource 'http://my-url.com/assets/visual-climate-e62bc38bf7f8222ada28c3610ca3fc0c.js' with computed SHA-256 integrity 'rmy5bIbd1VtZvKFFNrowA8t7HzdFGJzV5tOFMqMQ8yE='. The resource has been blocked.

编辑2:

我在integrity=""暂时添加了index.html,似乎用index.html替换了所有资产文件。我相信这实际上是导致问题的原因。

编辑3:

我暂时将资产转移到了Rails&#39;公用文件夹,应用程序工作。看起来在如何处理S3上的资产文件方面存在问题。我正在添加deploy.js文件,以防它配置不正确。

deploy.js:

module.exports = function(deployTarget) {
  var ENV = {};

  if (deployTarget === 'development-postbuild') {
    ENV.plugins = ['redis'];

    ENV.build = {
      environment: 'development'
    };

    ENV.redis = {
      keyPrefix: 'my-app',
      revisionKey: '__development__',
      allowOverwrite: true,
      host: 'localhost',
      port: 6379,
      distDir: function(context) {
        return context.commandOptions.buildDir;
      }
    };
  }

  if (deployTarget === 'production') {
    ENV.build = {
      environment: 'production'
    };

    ENV.pipeline = {
      activateOnDeploy: true
    };

    ENV['ssh-tunnel'] = {
      username: process.env['SSH_USERNAME'],
      host: process.env['REDIS_HOST'],
      srcPort: process.env['REDIS_PORT']
    };

    ENV.redis = {
      keyPrefix: 'my-app',
      allowOverwrite: true,
      host: 'localhost',
      port: process.env['REDIS_PORT']
    };

    ENV.s3 = {
      accessKeyId: process.env['AWS_ACCESS_KEY'],
      secretAccessKey: process.env['AWS_SECRET_KEY'],
      bucket: 'my_app_bucket',
      region: 'us-west-2'
    };
  }

  return ENV;
};

我使用ember-deploy-demo中使用的相同选项,因为它似乎与我使用的设置相同。

0 个答案:

没有答案