在正在运行的Play应用程序中获取所有活动的路径/路径

时间:2014-10-20 12:42:21

标签: scala playframework playframework-2.3

是否有一种标准方法可以在播放应用程序中获得所有可能的(当然不包括通配符)路径/路径?

我可以用

做到
Play.current.routes.map( _.documentation.map(_._2))

它给了我所有可用的路线,但它对我来说看起来有点笨拙。

1 个答案:

答案 0 :(得分:2)

仅仅是为了详细阐述,我所做的就是这个(正是你所做的):

  val myroutes = Play.current.routes map (routes => routes.documentation) getOrElse (Nil)
  myroutes foreach { r =>
    println("%-10s %-50s %s".format(r._1, r._2, r._3))
  }

我也得到了:

GET        /                                                  controllers.Application.index
GET        /apis                                              controllers.Application.apis
GET        /docs                                              controllers.Application.docs
GET        /sampleapi/status/$id<[^/]+>                       controllers.SampleAPI.status(id:String)
GET        /city/$id<[^/]+>                                   controllers.CityAPI.findById(id:Long)
GET        /city1/$id<[^/]+>                                  controllers.CityAPI.findById1(id:Long)
GET        /apps/authorize/                                   controllers.Apps.authorize
POST       /apps/send_auth/                                   controllers.Apps.send_auth
GET        /clients/                                          controllers.Clients.list
GET        /client/new                                        controllers.Clients.create
POST       /client/add                                        controllers.Clients.add
POST       /client/update                                     controllers.Clients.update
GET        /client/edit/$id<[^/]+>                            controllers.Clients.edit(id:String)
PUT        /client/                                           controllers.Clients.update
GET        /client/$id<[^/]+>                                 controllers.Clients.get(id:String)
DELETE     /client/$id<[^/]+>                                 controllers.Clients.delete(id:String)
GET        /login                                             controllers.Auth.login
POST       /authenticate                                      controllers.Auth.authenticate
GET        /logout                                            controllers.Auth.logout
POST       /oauth2/access_token                               controllers.OAuth2Controller.accessToken
GET        /webjars/$file<.+>                                 controllers.WebJarAssets.at(file:String)
GET        /assets/$file<.+>                                  controllers.Assets.at(path:String = "/public", file:String)

这还包括webjar和资源路径,因此您可能希望将其过滤掉。