Play Framework:如何路由到公用文件夹中的HTML页面

编程入门 行业动态 更新时间:2024-10-28 10:28:23
本文介绍了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 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)

以上路线按预期运行

  • localhost/mymodule/swagger-ui被路由到localhost/mymodule/swagger-ui/index.html
  • localhost/mymodule/swagger-ui/index.html根本没有路由,向最终用户隐藏了index.html
  • index.html中的相对路径被路由到localhost/mymodule/swagger-ui/css/*
  • localhost/mymodule/swagger-ui is routed to localhost/mymodule/swagger-ui/index.html
  • localhost/mymodule/swagger-ui/index.html is not routed at all, hiding index.html to end users
  • Relative paths in index.html are routed to localhost/mymodule/swagger-ui/css/*
  • 我希望能帮上忙.

    更多推荐

    Play Framework:如何路由到公用文件夹中的HTML页面

    本文发布于:2023-07-12 07:23:39,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1096845.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:路由   页面   文件   夹中   Play

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!