Skip to content

Commit

Permalink
fix: change --allowed-origins to be actually optional
Browse files Browse the repository at this point in the history
  • Loading branch information
jahrim committed Sep 12, 2023
1 parent 2672b05 commit 75eba89
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,26 @@ class ChessGameHttpAdapter(
override protected def init(context: AdapterContext[ChessGamePort]): Unit =
val router = Router.router(context.vertx)

val cors: CorsHandler =
CorsHandler
.create()
.addOrigins(allowedOrigins.asJava)
.allowCredentials(true)
.allowedMethods(
Set(
HttpMethod.HEAD,
HttpMethod.GET,
HttpMethod.POST,
HttpMethod.PUT
).asJava
if allowedOrigins.nonEmpty then
router
.route()
.handler(
CorsHandler
.create()
.addOrigins(allowedOrigins.asJava)
.allowCredentials(true)
.allowedMethods(
Set(
HttpMethod.HEAD,
HttpMethod.GET,
HttpMethod.POST,
HttpMethod.PUT
).asJava
)
)

router
.route()
.handler(cors)
.handler(BodyHandler.create())
.handler(LogHandler(context.log.info))
.failureHandler(context => context.sendException(context.failure))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ class Args(private val arguments: Seq[String]) extends ScallopConf(arguments):
descr = "A list of colon separated origins that are allowed to access this service.",
default = Some(""),
required = false
).map(_.split(";").toSeq)
).map(_.split(";").filter(_.nonEmpty).toSeq)
verify()

0 comments on commit 75eba89

Please sign in to comment.