播放从conf文件夹中读取路由的框架文件 [英] play framework reading file from conf folder with routing
问题描述
我有一个带有Play框架的Web应用程序.应用程序中使用的所有图像都保存在公用文件夹中,并可以通过conf/route文件中定义的路由进行访问.因此,构建后,我使用的所有图像都存在jar文件中.但是我的要求是,管理员将放置少量UI应该可以访问的图像.出于明显的原因,我可以要求他们将图像添加到jar中.
I have a web application with play framework. All images used in the application are kept in public folder and are accessed with the help of a routing defined in the conf/route file. So all the images I used are present in a jar file after build. But my requirement is that the admin will be placing few images that the UI should be able to access. For obvious reasons I can ask them to add images into the jar.
我的计划是请管理员将图像添加到conf文件夹内的文件夹中,然后使用路由从那里读取它(我相信这是可能的,因为当前有一个路由定义已从配置文件中读取json). /p>
My plan is to ask the admin to add images to a folder inside the conf folder and read it from there using routing (I believe its possible because currently there is a routing defined that's reading a json from the config file).
# Home page
GET / controllers.Application.index
GET /clientConfig controllers.Application.clientConfiguration
GET /testImg controllers.Application.testImg
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
对于Play框架来说是全新的东西,我想不出一种方法来为此定义路由并从conf文件夹内的文件夹中读取图像.任何帮助都将受到高度赞赏.
Being totally new to Play framework I can't figure out a way to define routes for that and read images from a folder inside the conf folder . Any help is highly appreciated.
推荐答案
正如LiorH所说,通常不建议将conf文件夹公开.但是,如果这确实是您想要的,那么您可以尝试实现自己的控制器.
As LiorH said, it's usually not a good idea to expose conf folder to public. But if this is really what you want, then you can try to implement your own controller.
在您的route
文件中:
GET /configuration ConfController.loadConf(path)
在ConfController
中:
def loadConf(path: String) = Action {
Ok.sendFile(Play.getFile("conf$path"))
}
这篇关于播放从conf文件夹中读取路由的框架文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!