在 sinatra 的 public 目录中获取静态资产导致 404?

get static assets in sinatra's public directory results in 404?

我正在使用 jQuery (3.1.0) 的最新压缩 CDN 版本,并且在我的 /public 目录中有一个 json 文件,我正在尝试GET 并登录到控制台。我这样做的三行是:

$.getJSON("/public/data.json", function(json) {
  console.log(json);
});

这只会给出 404:Failed to load resource: the server responded with a status of 404 (Not Found)

我可以将 json 作为 JavaScript 对象添加到我的 erb 文件中并从那里开始工作,但我宁愿它是自己的单独文件。

为什么我会收到 404?

删除 /public/

没有必要。

Public 被视为顶级目录