如何在 Heroku 上提供嵌套静态内容?

发布于 2024-08-29 09:44:29 字数 505 浏览 5 评论 0 原文

我有一个 Rails 应用程序,其静态内容位于 public 目录(例如 public/index.html)中,并且在嵌套子目录中包含其他静态内容(例如 public/one/两个/index.html)。

如果我通过 script/server 在本地运行所有静态内容,但当我将其上传到 Heroku 时,所有静态内容都会正确提供 顶级页面加载正确,但嵌套内容返回 404。

我找到了许多资源(例如 这个问题)讨论了 Rails 中的静态内容,但它们似乎都假设一个相当简单的结构,只有一个目录包含所有文件。

有什么办法可以解决这个问题吗?

I have a rails application with static content in the public directory (e.g. public/index.html) and additional static content in nested subdirectories (e.g. public/one/two/index.html).

All the static content is served correctly if I run it locally via script/server but when I upload it to Heroku the top-level page loads correctly but the nested content returns a 404.

I've found a number of resources (for example this question) which discuss static content in rails but they all seem to assume a fairly simple structure with a single directory containing all the files.

Is there any way I can fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾城°AllureLove 2024-09-05 09:44:29

如果您有一个非常简单的 Web 应用程序(例如,主要包含静态内容),则在 Sinatra “http://heroku.com” rel="nofollow noreferrer">Heroku 的设置要简单得多,并且可以防止此类问题。

If you have a very simple web application (with mostly static content, say) then using Sinatra on Heroku is much simpler to set up and prevents this type of problem.

风月客 2024-09-05 09:44:29

您可以在 Heroku 上提供静态内容,而无需编写任何“代码”...您只需告诉“Rack”中间件内容在哪里(如本帮助文章中所述):

http://devcenter.heroku.com/articles/static-sites-on-heroku

You can serve up static content on Heroku without writing any "code" at all... you just need to tell the "Rack" middleware where the content is (as detailed in this help article):

http://devcenter.heroku.com/articles/static-sites-on-heroku

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文