如何解决资产未与Heroku和Cloudflare一起使用
我有一个ruby on rails 6
应用程序正在heroku上运行,我正在将其设置为在自定义域上运行。我做了以下
heroku domains:add www.example.com
heroku domains:add example.com
heroku domains # noted the herokudns.com names for www.example.com and example.com
# in cloudflare added cnames for www.example.com and example.com
# in cloudflare,checked the example.com cname is flattened
heroku config:set APPLICATION_HOST=www.example.com
heroku config:set ASSET_HOST=www.example.com
当我访问www.example.com
时,我看到原始的html,但是没有样式。但是在日志中我看到了
2020-08-22T05:42:36.262127+00:00 heroku[router]: at=info method=GET path="/packs/js/application-aaf9d9c806bf765590e6.js" host=www.example.com request_id=e833945b-54bc-4d4a-bbf7-d7c502444b15 fwd="2001:8003:2d82:b901:5821:c882:4a71:5ba0,108.162.250.97" dyno=web.1 connect=0ms service=6ms status=200 bytes=302 protocol=https
2020-08-22T05:42:36.261767+00:00 heroku[router]: at=info method=GET path="/assets/application-90a7667ebe1530b7281dc7743ca54268ab23286f578c9a356684ecd84321b0fd.css" host=www.example.com request_id=d2ffabfa-fe6e-4ef9-b6a4-d8bd771181dc fwd="2001:8003:2d82:b901:5821:c882:4a71:5ba0,108.162.250.69" dyno=web.1 connect=0ms service=8ms status=200 bytes=331 protocol=https
如果我在<head>
标签中查看页面的源代码,
<link rel="stylesheet" media="all" href="https://www.philomaths.org/assets/application-90a7667ebe1530b7281dc7743ca54268ab23286f578c9a356684ecd84321b0fd.css" />
<script src="https://www.philomaths.org/packs/js/application-aaf9d9c806bf765590e6.js"></script>
因此,正在加载正确的资产文件。但是当我查看资产文件时,js和css都是空的。
我该如何解决?
解决方法
我做了一个较小的更改并将其推送到heroku以确保其正确编译,并且看到了此消息
remote: You set `config.action_dispatch.x_sendfile_header = 'X-Sendfile'` in production,remote: but you do not have `apache` installed on this app. This setting will cause any assets
remote: being served by your application to be returned without a body.
remote:
remote: To fix this issue,please set:
remote:
remote: config.action_dispatch.x_sendfile_header = nil
我意识到我没有正确设置the x_sendfile_header
。我在production.rb中修复了它,
然后将其推送到heroku,但仍然是同样的问题。
然后我使用了heroku repo:reset
和heroku repo:purge_cache
命令,重置了Cloudflare缓存,并清除了我的浏览器缓存,然后...它现在可以工作了!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。