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

Nested routes serve routes on all nested paths #3243

Open
amumurst opened this issue Dec 9, 2024 · 0 comments
Open

Nested routes serve routes on all nested paths #3243

amumurst opened this issue Dec 9, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@amumurst
Copy link

amumurst commented Dec 9, 2024

Describe the bug
The feature of nesting routes is exposing paths on both the original path, and on the nested path.
https://zio.dev/zio-http/reference/routing/routes#nested-routes

To Reproduce
I found it by curl-ing my app, but here is a reproducer using both the direct request syntax and calling the server directly

//> using dep "dev.zio::zio-http:3.0.1"
import zio.*
import zio.http.*
import zio.http.codec.PathCodec

object HelloWorld extends ZIOAppDefault:
  val routed = PathCodec.literal("foo") / Routes(
    Method.GET / "hello" -> handler(Response.text("World"))
  )
  val hello = Request.get("http://localhost:8080/hello")
  val fooHello = Request.get("http://localhost:8080/foo/hello")
  override def run = {
    for {
      res1 <- routed.runZIO(hello).debug //Gives OK
      res2 <- routed.runZIO(fooHello).debug //Gives OK
      p <- Server.serve(routed).forkDaemon
      res3 <- Client.batched(hello).debug //Gives OK
      res4 <- Client.batched(fooHello).debug //Gives OK
      _ <- p.interrupt
    } yield ()
  }.provide(Server.default ++ Client.default)

Expected behaviour
Only the requests to fooHello respond with 200 OK, with the requests to hello giving 404.

@amumurst amumurst added the bug Something isn't working label Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant