问题描述
以下是我的应用程序布局:
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)
以上路线按预期运行
-
http://localhost/mymodule/swagger-ui
被路由到http://localhost/mymodule/swagger-ui/index.html
-
http://localhost/mymodule/swagger-ui/index.html
根本没有路由,向最终用户隐藏了index.html
-
index.html
中的相对路径被路由到http://localhost/mymodule/swagger-ui/css/*
http://localhost/mymodule/swagger-ui
is routed tohttp://localhost/mymodule/swagger-ui/index.html
http://localhost/mymodule/swagger-ui/index.html
is not routed at all, hidingindex.html
to end users- Relative paths in
index.html
are routed tohttp://localhost/mymodule/swagger-ui/css/*
我希望能帮上忙.
这篇关于Play Framework:如何路由到公用文件夹中的HTML页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!