3

I've got a series of paths that look like;

path("slides" / Segment) { segment =>
  getFromDirectory(s"${cfg.slidesDir}/$segment")
} ~
path("foo" / Segment) { segment =>
  getFromDirectory(s"${cfg.mypyPursDir}/$segment")
} ~
path("foo" / "images" / Segment) { segment =>
  getFromDirectory(s"${cfg.mypyPursImageDir}/$segment")
}

Under certain runtime conditions, some of these may not be active (e.g. production versus dev system). How does one enable this conditionality? I can imagine encoding it with if-else if there was a "dummy path" that didn't do anything, for instance.

bbarker
  • 11,636
  • 9
  • 38
  • 62

1 Answers1

5

Create a List of all the routes you want using standard Scala filtering and List building operations. Then use concat to create a route that includes all the selected routes.

val allRoutes: List[Route] = ???
val activeRoutes = allRoutes.filter(???)

def route =
  concat(activeRoutes:_*)

I prefer concat to ~ for chaining routes.

Tim
  • 26,753
  • 2
  • 16
  • 29