Created
May 9, 2018 20:18
-
-
Save pcejrowski/2189f86e7f2a808a3786575b2973a5c1 to your computer and use it in GitHub Desktop.
Play Embedded Server with routings in different submodules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
play.http.secret.key="weirdsecret" | |
play.http.secret.key=${?APPLICATION_SECRET} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inThisBuild(List( | |
organization := "com.example", | |
scalaVersion := "2.12.6", | |
version := "0.1.0-SNAPSHOT" | |
)) | |
lazy val root = (project in file(".")) | |
.settings(name := "play-server") | |
.aggregate(module, server) | |
lazy val module = (project in file("module")) | |
.settings( | |
libraryDependencies ++= Seq( | |
"com.typesafe.play" %% "play-server" % "2.6.13" % Provided | |
) | |
) | |
lazy val server = (project in file("server")) | |
.settings( | |
libraryDependencies ++= Seq( | |
"com.typesafe.play" %% "play-akka-http-server" % "2.6.13" | |
) | |
) | |
.dependsOn(module) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import play.api.mvc._ | |
import play.api.routing.sird._ | |
import play.api.routing.{Router, SimpleRouter} | |
object ModuleEndpoints extends SimpleRouter { | |
def routes: Router.Routes = { | |
case GET(p"/getendpoint") => Action { req => | |
Results.Ok("/getendpoint in ModuleEndpoints") | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import play.api.routing.Router | |
import play.core.server.{AkkaHttpServer, ServerConfig} | |
object MyServer extends App { | |
val routes = Map( | |
"/module" -> ModuleEndpoints, | |
"/server" -> ServerEndpoints | |
) | |
val server = AkkaHttpServer.fromRouter(ServerConfig(port = Some(8080)))(routes) | |
implicit def combine(routers: Map[String, Router]): Router.Routes = | |
routers | |
.map { case (prefix, router) => router.withPrefix(prefix).routes } | |
.reduceLeft(_ orElse _) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import play.api.mvc._ | |
import play.api.routing.sird._ | |
import play.api.routing._ | |
object ServerEndpoints extends SimpleRouter { | |
def routes: Router.Routes = { | |
case GET(p"/getendpoint") => Action { req => | |
Results.Ok("/getendpoint in ServerEndpoints") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment