【发布时间】:2024-08-10 08:25:02
【问题描述】:
我正在使用 Plug.Static 从我的服务器提供静态文件。这样做的“默认”方式是像这样配置它:
plug Plug.Static,
at: "/my_project/assets",
from: :my_project,
gzip: true
然后我可以在 html 中使用 priv/static 中的文件,例如:
<img class='picture' src='<%= static_path(@conn, "/myPicture.png") %>'>
到目前为止一切顺利。但是,如果我想在不同的路径提供来自 priv/static 的文件,我使用
plug Plug.Static,
at: "/my_project/another_path/assets",
from: :my_project,
gzip: true
现在我无法使用 static_path 访问文件,因为它仍然解析为 host.com/assets/my-picture-hash 而不是 host.com/another_path/assets/my-picture-hash,这是预期的行为。
当散列文件未在默认路径中公开时,如何获取其实际路径?
【问题讨论】: