Last active
June 25, 2023 15:33
-
-
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
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 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