未找到heroku资产404 [英] heroku assets not found 404

查看:170
本文介绍了未找到heroku资产404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在处理一个问题,即我们的资产正在编译slu comp编译期间没有任何问题。然而,从昨天开始,我们正在推进我们的分段和生产应用程序,现在我们遇到了浏览器指出资产因某些原因无法加载的问题。



使用浏览器开发工具,我们看到这个错误:
无法加载资源:服务器响应状态为404(未找到):
/assets/application-a3b17e738ce8996d058795310e3cd9b4.js



我们决定做的第一件事是将我们的代码库回滚到最后一次提交(这是在以前的heroku推送中完全可用的提交)。同样的问题存在于浏览器无法加载资源的地方。



使用bash,我连接到heroku实例并检出public / assets目录以确保资产实际上在那里。它们都在那里,在文件名之前有正确的哈希码。这些文件不是空的,清单文件看起来不错。
我不确定此时还有什么要尝试的。加载资产之前,我们从未遇到过问题。在heroku推送日志中没有任何内容表明任何事情在任何时候都会抛出错误。 我有同样的问题。在我的生产宝石中包含 rails_12factor gem(在我的Gemfile中)后,它似乎对我来说是固定的。在阅读Heroku支持页面的第一部分后,我发现了这一点: https://devcenter.heroku.com/ articles / rails4


记录和资产



Heroku将日志作为流并且要求您的日志被发送到STDOUT。要在Rails 4中启用STDOUT日志记录,您可以添加rails_12factor gem。这个宝石还将配置您的应用程序在生产中服务资产。要添加此Gem,请将它添加到您的Gemfile中:

gem'rails_12factor',group :: production

宝石可以让你的应用程序更接近于12因子应用程序。您可以获取有关gem如何配置日志记录和资产的更多信息,以读取rails_12factor README。如果您的应用程序中没有该宝石,您将在部署时收到警告,并且您的资产和日志将无法正常运行。


'rails_12factor'gem对 rails_serve_static_assets gem和 rails_stdout_logging 具有gem依赖关系。基本上,如果您不希望Rails应用程序在处理请求时使用其宝贵周期来处理资源,那么您需要找出不同的解决方案,例如CDN: https://devcenter.heroku.com/articles/using-amazon-cloudfront-cdn-with-rails

We are dealing with an issue where our assets are compiling w/o any issues during slug compilation. However, starting yesterday after a push to both our staging and production applications, we are now running into issues where the browser is indicating that the assets can't load for some reason.

Using the browser dev tools we are seeing this error: Failed to load resource: the server responded with a status of 404 (Not Found) : /assets/application-a3b17e738ce8996d058795310e3cd9b4.js

The first thing we decided to do was rollback our codebase to the last commit (which was the commit that was fully functional in a previous heroku push). The same issue exists where the browser can't load the asset.

Using bash, I connected to the heroku instance and checked out the public/assets directory to ensure the assets were actually there. They are ALL there with the correct hash codes preceding the file names. The files are not empty and the manifest file looks good to go. I'm not sure what else to try at this point. We've never had issues until now with loading of assets. There is nothing in the heroku push logs that indicate anything is throwing an error at any point.

解决方案

I had the same issue. It seems to be fixed for me after including the rails_12factor gem in my production gems (in my Gemfile). I found this out after reading the first part of this Heroku Support page: https://devcenter.heroku.com/articles/rails4

Logging and assets

Heroku treats logs as streams and requires your logs to be sent to STDOUT. To enable STDOUT logging in Rails 4 you can add the rails_12factor gem. This gem will also configure your app to serve assets in production. To add this gem add this to your Gemfile:

gem 'rails_12factor', group: :production

This gem allows you to bring your application closer to being a 12factor application. You can get more information about how the gem configures logging and assets read the rails_12factor README. If this gem is not present in your application, you will receive a warning while deploying, and your assets and logs will not be functional.

The 'rails_12factor' gem has gem dependencies on the rails_serve_static_assets gem and rails_stdout_logging. Basically, if you don't want your Rails app using its precious cycles on processing requests just to serve assets then you'll need to figure out a different solution such as a CDN: https://devcenter.heroku.com/articles/using-amazon-cloudfront-cdn-with-rails

这篇关于未找到heroku资产404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆