scala – 如何在finagle中托管静态资源
发布时间:2020-12-16 18:12:17 所属栏目:安全 来源:网络整理
导读:我试图在finagle中托管静态资源,如 javascript和css文件. 我已经设法让它工作,但我必须专门配置我的路由服务中的资源文件夹的每个路由.例如: def build():RoutingService[Request with Request] = { val routingService = RoutingService.byPathObject { ca
我试图在finagle中托管静态资源,如
javascript和css文件.
我已经设法让它工作,但我必须专门配置我的路由服务中的资源文件夹的每个路由.例如: def build():RoutingService[Request with Request] = { val routingService = RoutingService.byPathObject { case Root => ControllerRegistry.rootController.root() case Root / "public" / resource => ControllerRegistry.publicController.findPublic() case Root / "public" / "bootstrap"/ "css" / resource => ControllerRegistry.publicController.findPublic() } routingService } 和 def findPublic(): Service[Request,Response] = { val findPublic = new Service[Request,Response] { def apply(request: Request) = { Future { val resource = Path(request.path) match { case Root / "public" / resource => getResourceText(s"/public/$resource") case Root / "public" / "bootstrap" / "css" / resource => getResourceText(s"/public/bootstrap/css/$resource") case _ => throw new IllegalStateException } val response = Response() response.setContent(copiedBuffer(resource,UTF_8)) response } } } findPublic } 现在我可以在public和public / bootstrap / css中获取任何资源,但是如果没有更多配置,我就无法获得public / bootstrap / js. 解决方法
TLDR:Finagle并不是你想做的事情的正确库.你可以使用类似
Finatra的东西,它建立在finagle之上.
长版: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |