Play Framework:如何路由到公用文件夹中的HTML页面 [英] Play Framework: How to route to a HTML page in the public folder

查看:274
本文介绍了Play Framework:如何路由到公用文件夹中的HTML页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的应用程序布局:

Here below is my application layout:

myapp
  + app
  + conf
  + modules
  |   + mymodule
  |       + app
  |       + conf
  |       + public
  |           + swagger-ui
  |                + css
  |                + images
  |                + index.html
  + public
  + ...

我想用URL http://localhost/mymodule/swagger-ui加载index.html ...以下是我在modules/mymodule/conf/mymodule.routes中的路线:

I want to load index.html with url http://localhost/mymodule/swagger-ui... and here below are my routes in modules/mymodule/conf/mymodule.routes:

...

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file       controllers.mymodule.Assets.at(path = "/public", file)
GET /swagger-ui         controllers.mymodule.Assets.at(path = "/public/swagger-ui", file = "index.html")

以上路由工作正常,只是未找到index.html引用的资源(图像,css).如果我这样修改路线...

The routes above work... except that the resources (images, css) referenced by index.html are not found. If I modify the routes like this...

...

GET /assets/*file       controllers.mymodule.Assets.at(path = "/public", file)
GET /swagger-ui/*file   controllers.mymodule.Assets.at(path = "/public/swagger-ui", file)

...然后按预期方式工作,并且引用的资源也已加载...但是,当然,我需要提供一个http://localhost/mymodule/swagger-ui/index.html这样的网址.

... then it works as expected and referenced resources are also loaded... but of course I need to provide an url like http://localhost/mymodule/swagger-ui/index.html.

有什么建议吗?

推荐答案

我已经尝试了James的建议–我认为是更合理的解决方案...

I've tried what James suggested – and in my opinion was the solution that made more sense...

GET     /swagger-ui         controllers.apidocs.Assets.at(path = "/public/swagger-ui", file = "index.html")
GET     /swagger-ui/*file   controllers.apidocs.Assets.at(path = "/public/swagger-ui", file)

...但实际上它仅部分起作用,即http://localhost/mymodule/swagger-ui已正确路由到http://localhost/mymodule/swagger-ui/index.html,但随后其中包含的所有相对路径(例如css/highlight.default.css)都被路由到http://localhost/mymodule/css/*而不是http://localhost/mymodule/swagger-ui/css/*.就是说,要使其正常工作,我必须像这样修改路由:

... but actually it only worked partially, i.e. http://localhost/mymodule/swagger-ui was correctly routed to http://localhost/mymodule/swagger-ui/index.html, but then all the relative paths contained in it (e.g. css/highlight.default.css) were routed to http://localhost/mymodule/css/* instead of to http://localhost/mymodule/swagger-ui/css/*. That said, to make it work I had to modify the routes like this:

GET     /swagger-ui         controllers.apidocs.Assets.at(path = "/public/swagger-ui", file = "index.html")
GET     /*file              controllers.apidocs.Assets.at(path = "/public/swagger-ui", file)

以上路线按预期运行

  1. http://localhost/mymodule/swagger-ui被路由到http://localhost/mymodule/swagger-ui/index.html
  2. http://localhost/mymodule/swagger-ui/index.html根本没有路由,向最终用户隐藏了index.html
  3. index.html中的相对路径被路由到http://localhost/mymodule/swagger-ui/css/*
  1. http://localhost/mymodule/swagger-ui is routed to http://localhost/mymodule/swagger-ui/index.html
  2. http://localhost/mymodule/swagger-ui/index.html is not routed at all, hiding index.html to end users
  3. Relative paths in index.html are routed to http://localhost/mymodule/swagger-ui/css/*

我希望能帮上忙.

这篇关于Play Framework:如何路由到公用文件夹中的HTML页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆