Last active
February 3, 2026 20:18
-
-
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/928b2f4da1d21a11d7e0db15446cd202f8b30f08
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
| // 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 License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // 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