通过 Plug.Conn.send_file 提供 SPA

Serving a SPA via Plug.Conn.send_file

我按照此处的决议通过 Phoenix 提供我的 SPA:

当我移动到发布版本时,spa 结束在一个具有版本名称的目录中,例如: /opt/appname/lib/appname-0.0.1/priv/static/index.html

这似乎是一种脆弱的方法,因为每次发布新版本的应用程序时,新版本都会导致此 link 中断。

是否可以通过相对路径为应用提供服务?

因为它在 priv for app_name 目录中,您可以这样做:

Application.app_dir(:app_name, "priv/static/index.html")

这将 return 一个基于 app_name 位置的完整路径,即使您四处移动项目也应该有效。