【发布时间】:2016-08-26 13:42:01
【问题描述】:
我正在将我们的应用程序从 Play 2.3.x 迁移到 2.4.x。随着从静态路由的迁移,我显然失去了重定向到某些资产的能力。该应用程序实现了一个租户功能,该功能可以附加到 url (localhost:9000/Tenant/),它会将您重定向到登录页面,并在后台设置适当的租户。默认租户(用于开发目的)可以通过不使用 url (localhost:9000/) 的附件来访问。
现在的问题是,在设置租户后,我使用以下内容重定向到 app/index.html:
return redirect(query != null ? "app/index.html?" + query : "app/index.html");
重定向有效,但不幸的是我得到“找不到操作 请求'GET /app/index.html'”。如果我手动重定向,我也无法访问资产。
在应用程序的路由文件中,以下路由条目应该正确处理此重定向,我错了吗?
# Map static resources from the /public/app folder to the /app URL path
GET /app/*file controllers.Assets.at(path="/public/app", file)
不幸的是,日志没有说什么特别的,除了:
**** [TRACE] Http request received by netty: DefaultHttpRequest(chunked: false)
**** GET /app/index.html HTTP/1.1
**** Host: localhost:9000
**** Connection: keep-alive
**** Upgrade-Insecure-Requests: 1
**** User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
**** Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
**** Accept-Encoding: gzip, deflate, sdch
**** Accept-Language: en-US,en;q=0.8,de;q=0.6
**** Cookie: PLAY_SESSION="f2069c9ef539f8d3fe9d07327a3c65bd4a45cb79-MANDT=0B7ABE451F3441A5AB93799DBC8621EF" [play.core.server.netty.PlayDefaultUpstreamHandler]
**** [TRACE] Serving this request with: <function1> [play.core.server.netty.PlayDefaultUpstreamHandler]
**** [TRACE] Invoking action with request: GET /app/index.html [play.api.mvc.Action]
我在其他情况下看到 [Play Framework Routes not working] 人们在控制台上收到错误消息,指出已尝试了哪些路由。
这在 2.3.x 中有效,但在 2.4.x 中不再有效。我错过了什么吗?
【问题讨论】:
-
只有重定向的时候出现这个问题? (即,如果您直接在浏览器中访问 /app/index.html,它可以工作吗?)
-
GET /app/*file controllers.Assets.at(path="/public", file)你能试试这个吗,你检查redirect可以处理 1 行 if 语句吗? -
@Salem:问题不仅在于重定向时,而且似乎与每次调用 index.html 时有关。
-
@alican.balik:index.html 并不直接在 public 文件夹中,我们在其中有一个额外的 app 文件夹。单行 if 语句在以前的版本中有效,现在似乎也有效。
标签: java playframework