Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active June 25, 2023 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacr/2b07ab44991fd5b3066be27f227394a2 to your computer and use it in GitHub Desktop.
Save dacr/2b07ab44991fd5b3066be27f227394a2 to your computer and use it in GitHub Desktop.
Simplest static resources http server example using akka-http framework. / published by https://github.com/dacr/code-examples-manager #ee2cec8a-c010-4a71-ada1-ba418fe8054a/a659e6850a8e12224e5c6057ac0333f7759bf6cd
// summary : Simplest static resources http server example using akka-http framework.
// keywords : scala, actors, akka-http, http-server
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : ee2cec8a-c010-4a71-ada1-ba418fe8054a
// created-on : 2018-06-30T15:43:05Z
// managed-by : https://github.com/dacr/code-examples-manager
// execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc'
import $ivy.`com.typesafe.akka::akka-http:10.2.4`
import $ivy.`com.typesafe.akka::akka-stream:2.6.13`
import akka.http.scaladsl._
import akka.http.scaladsl.server.Directives._
import scala.concurrent.Await
import scala.concurrent.duration.Duration
object StaticServer {
implicit val system = akka.actor.ActorSystem("MySystem")
implicit val executionContext = system.dispatcher
val routes = pathPrefix("browse") { getFromBrowseableDirectory(".") }
Http().newServerAt("0.0.0.0", 8080).bind(routes).andThen{case _ => println("Ready.")}
}
Await.ready(StaticServer.system.whenTerminated, Duration.Inf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment