Skip to content

Instantly share code, notes, and snippets.

@rossabaker
Forked from hvesalai/ScalatraServer.scala
Created October 24, 2011 20:21
Show Gist options
  • Save rossabaker/1310046 to your computer and use it in GitHub Desktop.
Save rossabaker/1310046 to your computer and use it in GitHub Desktop.
dsl proposal for embedded servers
object Main {
def main(args: Array[String]) {
MySquerylScheme.initialize()
WebServer("src/main/webapp", Config.webServerPort) { server =>
server.inContext("/api") { context =>
context.mount("validate", new ValidateApp)
context.mount("channels", new MessageChannelApp)
context.mount("streams", new StreamsApp)
context.mount("", new AccountApp)
}
server.mount("plans", new PlanApp) //mounts in root context
}
}
}
@WebListener class Bootstrap extends ServletContextListenerBootstrap {
def initialize(context: Context) {
MySquerylScheme.initialize()
context.mount("validate", new ValidateApp)
context.mount("channels", new MessageChannelApp)
context.mount("streams", new StreamsApp)
context.mount("", new AccountApp)
}
def destroy(context: Context) { }
}
trait Context {
def mount(path: String, app: App): Unit
def type: App
}
// Ugh, that name.
case class ServletContextContext(servletContext: ServletContext) extends Context {
type App = ScalatraServlet
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment