diff --git a/zio-http/shared/src/main/scala/zio/http/Routes.scala b/zio-http/shared/src/main/scala/zio/http/Routes.scala index 8695ebd2ea..2179bf9d8b 100644 --- a/zio-http/shared/src/main/scala/zio/http/Routes.scala +++ b/zio-http/shared/src/main/scala/zio/http/Routes.scala @@ -248,14 +248,18 @@ final case class Routes[-Env, +Err](routes: Chunk[zio.http.Route[Env, Err]]) { s val tree = self.tree Handler .fromFunctionHandler[Request] { req => + println(s"[DEBUG] Incoming request: Method = ${req.method}, Path = ${req.path}") + val chunk = tree.get(req.method, req.path) def allowedMethods = tree.getAllMethods(req.path) + println(s"[DEBUG] Chunk length for Method ${req.method} and Path ${req.path} = ${chunk.length}") + println(s"[DEBUG] Allowed methods for Path ${req.path} = ${allowedMethods.mkString(", ")}") req.method match { case Method.CUSTOM(_) => Handler.notImplemented case _ => if (chunk.isEmpty) { - if (allowedMethods.isEmpty) { + if (allowedMethods.isEmpty || allowedMethods == Set(Method.OPTIONS)) { // If no methods are allowed for the path, return 404 Not Found Handler.notFound } else { @@ -281,6 +285,7 @@ final case class Routes[-Env, +Err](routes: Chunk[zio.http.Route[Env, Err]]) { s } } } + } .merge }