Skip to content

Instantly share code, notes, and snippets.

@trane
Last active October 20, 2015 16:48
Show Gist options
  • Select an option

  • Save trane/53818c947c3777cf68fd to your computer and use it in GitHub Desktop.

Select an option

Save trane/53818c947c3777cf68fd to your computer and use it in GitHub Desktop.
// this is with POC (plain old curry)
// () => Filter
val loginPostService = new ExceptionFilter andThen
new ServiceFilter(serviceMatcher) andThen
new SessionIdFilter(sessionStore) andThen
new KeymasterLoginFilter(sessionStore) andThen
new KeymasterIdentityProvider(keymasterClient, Path(keymasterIdentityProviderPath))
// (ServerConfig) => Filter
val loginPostService: ServerConfig => Filter = config => {
new ExceptionFilter andThen
new ServiceFilter(config.serviceMatcher) andThen
new SessionIdFilter(config.sessionStore) andThen
new KeymasterLoginFilter(config.sessionStore) andThen
new KeymasterIdentityProvider(config.keymasterClient, Path(keymasterIdentityProviderPath))
}
val routingService1: ServerConfig => RoutingService = config => {
RoutingService.byMethodAndPathObject {
case Method.Post -> Root / "login" => loginPostService(config)
case Method.Get -> Root / "login" => loginGetService(config)
case _ => allOtherRequests(config)
}
}
Httpx.serve(...., routingService1(config))
// when we have a smart compiler (no java, your compiler sucks)
// we can have the compiler do the work for us
// () => Filter
val loginPostService = new ExceptionFilter andThen
new ServiceFilter(serviceMatcher) andThen
new SessionIdFilter(sessionStore) andThen
new KeymasterLoginFilter(sessionStore) andThen
new KeymasterIdentityProvider(keymasterClient, Path(keymasterIdentityProviderPath))
// (implicit ServerConfig) => Filter
def loginPostService(implicit config: ServerConfig): Filter =
new ExceptionFilter andThen
new ServiceFilter(config.serviceMatcher) andThen
new SessionIdFilter(config.sessionStore) andThen
new KeymasterLoginFilter(config.sessionStore) andThen
new KeymasterIdentityProvider(config.keymasterClient, Path(keymasterIdentityProviderPath))
val routingService1(implicit config: ServerConfig): RoutingService =
RoutingService.byMethodAndPathObject {
case Method.Post -> Root / "login" => loginPostService(config)
case Method.Get -> Root / "login" => loginGetService(config)
case _ => allOtherRequests(config)
}
implicit val config = ServerConfig(???, ???, ???, ???)
Httpx.serve(...., routingService1)
object ServerInstances {
implicits ...
}
object BpApp extends TwitterServer {
import ServerInstances._
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment