Skip to content

Instantly share code, notes, and snippets.

@elbowich
Created March 9, 2012 19:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save elbowich/2008342 to your computer and use it in GitHub Desktop.
Save elbowich/2008342 to your computer and use it in GitHub Desktop.
spray gateway
object Gateway {
import cc.spray.Directives._
import cc.spray.directives.Remaining
import cc.spray.client.HttpConduit
val conduit = new HttpConduit("localhost", 8080) // this will connect to the back-end
val route =
path("test-service" / Remaining) {
path => ctx => val headers = ctx.request.headers.filter(_.name != "Host")
val request = ctx.request.copy(uri = "/mock/" + path, headers = headers)
ctx complete conduit.sendReceive(request).map {
_.withHeadersTransformed(_.filter(_.name != "Date"))
}
} ~
pathPrefix("mock") {
_ complete "back-end response"
}
}
object Boot extends App {
import akka.actor.Actor._
import akka.actor.Supervisor
import akka.config.Supervision.{Supervise, SupervisorConfig, Permanent, OneForOneStrategy}
import cc.spray.{SprayCanRootService, HttpService}
import cc.spray.can.{HttpClient, HttpServer}
locally {
val httpClient = actorOf(new HttpClient())
val httpService = actorOf(new HttpService(Gateway.route))
val rootService = actorOf(new SprayCanRootService(httpService))
val httpServer = actorOf(new HttpServer())
Supervisor(
SupervisorConfig(
OneForOneStrategy(List(classOf[Exception]), 3, 100),
List(
Supervise(httpClient, Permanent),
Supervise(httpService, Permanent),
Supervise(rootService, Permanent),
Supervise(httpServer, Permanent)
)
)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment