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 binding in zio-http examples #2597

Merged
merged 1 commit into from
Nov 29, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import zio.http.{Server, ServerConfig}
import zio._
import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder, JsonDecoder, JsonEncoder}

import java.net.InetSocketAddress

object HelloWorldZioHttpServer extends ZIOAppDefault {
// a simple string-only endpoint
val helloWorld: PublicEndpoint[String, Unit, String, Any] =
Expand Down Expand Up @@ -40,5 +38,8 @@ object HelloWorldZioHttpServer extends ZIOAppDefault {

// starting the server
override def run =
Server.serve(app).provide(ServerConfig.live(ServerConfig().binding(new InetSocketAddress(8090))) >>> Server.default).exitCode
Server.serve(app).provide(
ServerConfig.live(ServerConfig.default.port(8090)),
Server.live,
).exitCode
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import zio.http.HttpApp
import zio.http.{Server, ServerConfig}
import zio.{ExitCode, Task, URIO, ZIO, ZIOAppDefault}

import java.net.InetSocketAddress

object ZioExampleZioHttpServer extends ZIOAppDefault {
case class Pet(species: String, url: String)

Expand Down Expand Up @@ -44,5 +42,11 @@ object ZioExampleZioHttpServer extends ZIOAppDefault {
val routes: HttpApp[Any, Throwable] = ZioHttpInterpreter().toHttp(List(petServerEndpoint) ++ swaggerEndpoints)

override def run: URIO[Any, ExitCode] =
Server.serve(routes).provide(ServerConfig.live(ServerConfig().binding(new InetSocketAddress(8080))) >>> Server.default).exitCode
Server
.serve(routes)
.provide(
ServerConfig.live(ServerConfig.default.port(8080)),
Server.live,
)
.exitCode
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import zio.http.HttpApp
import zio.http.{Server, ServerConfig}
import zio.{Task, ZIO, _}

import java.net.InetSocketAddress

/** Based on https://adopt-tapir.softwaremill.com zio version. */
object ZioMetricsExample extends ZIOAppDefault {

Expand Down Expand Up @@ -40,7 +38,10 @@ object ZioMetricsExample extends ZIOAppDefault {
_ <- Console.printLine(s"Server started at http://localhost:${serverPort}. Press ENTER key to exit.")
_ <- Console.readLine
} yield serverPort)
.provide(ServerConfig.live(ServerConfig().binding(new InetSocketAddress(port))) >>> Server.default)
.provide(
ServerConfig.live(ServerConfig.default.port(port)),
Server.live,
)
.exitCode
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import zio.http.{Server, ServerConfig}
import zio.Console.{printLine, readLine}
import zio.{Task, ZIO, ZIOAppDefault}

import java.net.InetSocketAddress

object RedocZioHttpServer extends ZIOAppDefault {
case class Pet(species: String, url: String)

Expand All @@ -32,7 +30,10 @@ object RedocZioHttpServer extends ZIOAppDefault {
printLine("Press any key to exit ...") *>
Server
.serve(petRoutes ++ redocRoutes)
.provide(ServerConfig.live(ServerConfig().binding(new InetSocketAddress(8080))) >>> Server.default)
.provide(
ServerConfig.live(ServerConfig.default.port(8080)),
Server.live,
)
.fork
.flatMap { fiber =>
readLine *> fiber.interrupt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import zio.http.{Server, ServerConfig}
import zio.{ExitCode, Schedule, URIO, ZIO, ZIOAppDefault}
import zio.stream._

import java.net.InetSocketAddress
import java.nio.charset.StandardCharsets
import java.time.Duration

Expand Down Expand Up @@ -42,5 +41,11 @@ object StreamingZioHttpServer extends ZIOAppDefault {

// Test using: curl http://localhost:8080/receive
override def run: URIO[Any, ExitCode] =
Server.serve(routes).provide(ServerConfig.live(ServerConfig().binding(new InetSocketAddress(8080))) >>> Server.default).exitCode
Server
.serve(routes)
.provide(
ServerConfig.live(ServerConfig.default.port(8080)),
Server.live,
)
.exitCode
}