【问题标题】:How to host static resources in finagle如何在 finagle 中托管静态资源
【发布时间】:2013-09-12 14:56:35
【问题描述】:

我正在尝试在 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
    }

现在我可以获取publicpublic/bootstrap/css 中的任何资源,但如果没有更多配置,我无法获取public/bootstrap/js

【问题讨论】:

    标签: scala finagle


    【解决方案1】:

    TLDR:Finagle 并不是完全适合你做你想做的事。你可以使用类似 Finatra 的东西,它是建立在 finagle 之上的。

    长版: Finagle 旨在构建分布式系统,它不是像 ruby​​ on rails 这样的 Web 框架(即使 finagle-http 提供了非常基本的功能)。它使构建相互交互的服务变得容易(并负责负载平衡、超时、断开连接、背压、分布式跟踪......) 在 Twitter,我们有一个基于 finagle 构建的 Web 框架库,但它尚未开源,同时您可以使用 Finatra

    【讨论】:

    • 现在我对这个内部网络框架很好奇 :) 未来有开源它的计划吗?
    猜你喜欢
    • 2012-09-07
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    • 1970-01-01
    • 2013-02-02
    • 2017-03-15
    • 1970-01-01
    相关资源
    最近更新 更多