以下是我的应用程序布局:
Here below is my application layout:
myapp + app + conf + modules | + mymodule | + app | + conf | + public | + swagger-ui | + css | + images | + index.html + public + ...我想用URL localhost/mymodule/swagger-ui加载index.html ...以下是我在modules/mymodule/conf/mymodule.routes中的路线:
I want to load index.html with url 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)...然后按预期方式工作,并且引用的资源也已加载...但是,当然,我需要提供一个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 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)...但实际上它仅部分起作用,即localhost/mymodule/swagger-ui已正确路由到localhost/mymodule/swagger-ui/index.html,但随后其中包含的所有相对路径(例如css/highlight.default.css)都被路由到localhost/mymodule/css/*而不是localhost/mymodule/swagger-ui/css/*.就是说,要使其正常工作,我必须像这样修改路由:
... but actually it only worked partially, i.e. localhost/mymodule/swagger-ui was correctly routed to localhost/mymodule/swagger-ui/index.html, but then all the relative paths contained in it (e.g. css/highlight.default.css) were routed to localhost/mymodule/css/* instead of to 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)以上路线按预期运行
我希望能帮上忙.
更多推荐
Play Framework:如何路由到公用文件夹中的HTML页面
发布评论