Playframework 播放框架:如何路由到公用文件夹中的HTML页面
以下是我的应用程序布局:Playframework 播放框架:如何路由到公用文件夹中的HTML页面,playframework,routes,Playframework,Routes,以下是我的应用程序布局: myapp + app + conf + modules | + mymodule | + app | + conf | + public | + swagger-ui | + css | + images | + index.html + public + ... 我
myapp
+ app
+ conf
+ modules
| + mymodule
| + app
| + conf
| + public
| + swagger-ui
| + css
| + images
| + index.html
+ public
+ ...
我想用url加载index.html
http://localhost/mymodule/swagger-ui
。。。下面是我在modules/mymodule/conf/mymodule中的路由
...
# 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)。如果我像这样修改路由
...
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
有什么建议吗?试试:
GET /swagger-ui controllers.Assets.at(path = "/public/swagger-ui", file = "index.html")
GET /swagger-ui/*file controllers.Assets.at(path = "/public/swagger-ui", file)
(订单事项)尝试:
GET /swagger-ui controllers.Assets.at(path = "/public/swagger-ui", file = "index.html")
GET /swagger-ui/*file controllers.Assets.at(path = "/public/swagger-ui", file)
(顺序很重要)我已经尝试了詹姆斯的建议——在我看来,解决方案更有意义
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/*
而不是tohttp://localhost/mymodule/swagger-ui/css/*
。也就是说,为了使其工作,我必须修改如下路线:
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/*
我希望这会有所帮助。我已经尝试了詹姆斯的建议——在我看来,这是一个更有意义的解决方案
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/*
而不是tohttp://localhost/mymodule/swagger-ui/css/*
。也就是说,为了使其工作,我必须修改如下路线:
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/*
我希望这能有所帮助。我更喜欢这样的重定向
GET /swagger-ui controllers.Default.redirect(to = "swagger-ui/")
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)
如果浏览到/swagger ui,它将重定向到swagger ui/因此接下来对js、css和图像的调用将位于正确的路径中我更喜欢这样的重定向
GET /swagger-ui controllers.Default.redirect(to = "swagger-ui/")
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)
如果您浏览到/swagger ui,它将重定向到swagger ui/因此对js、css和图像的下一次调用将位于正确的路径index.html文件中如何引用css/图像?它们的引用方式如下:images/logo.png、css/screen.css、,等等。什么是示例404错误URL?URL代替…index.html文件中如何引用CSS/图像?它们的引用方式如下:Images/logo.png、CSS/screen.CSS等。什么是示例404错误URL?URL代替…否。。。结果和以前一样。我认为值得一提的是,路线是一个游戏子项目的一部分-请参阅我的最新帖子。不。。。结果和以前一样。我的意思是,值得一提的是,这些路线是一个游戏子项目的一部分-见我的最新帖子。你的第一条路线和第二条路线有什么区别?你的确切意思是什么?”也就是说,为了让它起作用,我不得不修改这些路线:“我以为我错过了一个角色,但我对上面的两个路由文件示例进行了字符串比较,它们是相同的。有什么不同?它们在哪里相同?[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)]。第一个是将/swagger ui映射到index.html,而第二个是将任何其他文件映射到swagger ui目录中的相应文件。我不是指单独的行,而是指这两个代码段:第一个路由段和第二个路由段之间的区别是什么?确切的意思是什么?这就是说,为了使其正常工作,我不得不这样修改路由:“我以为我缺少了一个字符,但我对上面的两个路由文件示例进行了字符串比较,它们是相同的。有什么区别吗?它们在哪里是相同的?[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)]。第一个将/swagger ui映射到index.html,而第二个将任何其他文件映射到swagger ui目录中的相应文件。我不是指单独的行,而是指这两个代码段: