我有一个为 SPA 提供服务的 Play 框架应用程序。路由文件包含以下路由:
GET / controllers.Home.index
GET /index.html controllers.Home.index
# /api/* routes
GET /*file controllers.Assets.at(file)
controllers.Home.index
在执行 SSO 例程后提供 SPA 的索引。
当我在没有任何其他配置的情况下运行应用程序时,在访问 localhost:3000
和 localhost:3000/
时,index
操作将在 Home
Controller 按预期调用。
当我配置play.http.context
时,问题就开始了:
- 当设置为
/my-app
时,对localhost:3000/my-app
的请求成功;到localhost:3000/my-app/
返回 404。 - 当设置为
/my-app/
时,对localhost:3000/my-app
的请求返回 404;到localhost:3000/my-app/
成功。
有没有办法配置 Play,以便通过 controllers.Home.index
对两个 URL 的请求都成功?
最佳答案
我也在寻找同样的答案,但没有好的答案。对于 Play/Akka,这是 2 个不同的 URL,
选项 1) 就是定义它2x
GET /about controllers.HomeController.about
GET /about/ controllers.HomeController.about
选项 2) 将一个网址重定向到另一个网址
GET /a controllers.HomeController.about
GET /a/ controllers.Default.redirect(to = "/a")
选项 3) 更高级的方法,但我没有测试过
关于scala - Play 框架返回 404 并带有 play.http.context 和尾部斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60164601/