Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Port already Bind Error #57

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions zio-quickstart-restful-webservice/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ libraryDependencies ++= Seq(
)

resolvers ++= Resolver.sonatypeOssRepos("snapshots")

Compile / mainClass := Some("dev.zio.quickstart.MainApp")
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,33 @@ import zio.http._

object MainApp extends ZIOAppDefault:
def run =
Server
.serve(
GreetingRoutes() ++ DownloadRoutes() ++ CounterRoutes() ++ UserRoutes()
)
.provide(
Server.defaultWithPort(8080),
for {
serverFiber <- Server
.serve(
GreetingRoutes() ++ DownloadRoutes() ++ CounterRoutes() ++ UserRoutes()
)
.provide(
Server.defaultWithPort(8080),

// An layer responsible for storing the state of the `counterApp`
ZLayer.fromZIO(Ref.make(0)),
// An layer responsible for storing the state of the `counterApp`
ZLayer.fromZIO(Ref.make(0)),

// To use the persistence layer, provide the `PersistentUserRepo.layer` layer instead
InmemoryUserRepo.layer
)
// To use the persistence layer, provide the `PersistentUserRepo.layer` layer instead
InmemoryUserRepo.layer
)
.fork

// Add a shutdown hook to release the port on exit
_ <- ZIO.succeed {
java.lang.Runtime.getRuntime.addShutdownHook(new Thread {
override def run(): Unit = {
Unsafe.unsafe { implicit u =>
Runtime.default.unsafe.run(serverFiber.interrupt)
}
}
})
}

// Wait for the server to exit
_ <- serverFiber.join
} yield ()
Loading