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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] CORSInterceptor doesn't work with Vert.x server #3651

Open
susliko opened this issue Mar 30, 2024 · 0 comments
Open

[BUG] CORSInterceptor doesn't work with Vert.x server #3651

susliko opened this issue Mar 30, 2024 · 0 comments

Comments

@susliko
Copy link
Contributor

susliko commented Mar 30, 2024

Tapir version: 1.20.0

Scala version: 3.4.0

Describe the bug

Hi! 馃枛馃徎
Preflight requests are not processed by the server: 405 Method Not Allowed is returned instead of 204 No Content

How to reproduce?

//> using scala 3.4.0
//> using dep com.softwaremill.sttp.tapir::tapir-vertx-server:1.10.0

import sttp.tapir._
import sttp.tapir.server.vertx.VertxFutureServerInterpreter
import sttp.tapir.server.vertx.VertxFutureServerInterpreter._
import io.vertx.core.Vertx
import io.vertx.ext.web._
import scala.concurrent.{Await, Future}
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext
import sttp.tapir.server.vertx.VertxFutureServerOptions
import sttp.tapir.server.interceptor.cors.CORSInterceptor
import io.vertx.ext.web.handler.CorsHandler

@main
def tapirVertx =
  given ExecutionContext = scala.concurrent.ExecutionContext.Implicits.global
  val vertx = Vertx.vertx()

  val server = vertx.createHttpServer()
  val router = Router.router(vertx)

  // CORS works with native Vert.x handler
  // router.route().handler(CorsHandler.create())

  val myEndpoint = endpoint.get
    .in("path")
    .out(plainBody[String])
    .serverLogic(_ => Future(Right("OK")))

  val corsInterceptor = CORSInterceptor.default[Future]
  val opts = VertxFutureServerOptions.customiseInterceptors.corsInterceptor(
    corsInterceptor
  )
  val attach = VertxFutureServerInterpreter(opts.options).route(myEndpoint)
  attach(router)

  Await.result(server.requestHandler(router).listen(9000).asScala, Duration.Inf)

and then

curl -v -X OPTIONS http://localhost:9000/path -H 'Origin: http://my.origin' -H 'Access-Control-Request-Method: GET'

Additional information

My guess is that all routing is done inside vert.x Router and execution control is not passed to interceptors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant