Skip to content

Commit

Permalink
read the right cors plugin config on the transformError step
Browse files Browse the repository at this point in the history
  • Loading branch information
Zwiterrion committed Feb 19, 2025
1 parent 3434ba2 commit a7b7fac
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions otoroshi/app/next/plugins/cors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ class Cors extends NgRequestTransformer with NgPreRouting {
ctx: NgPreRoutingContext
)(implicit env: Env, ec: ExecutionContext): Future[Either[NgPreRoutingError, Done]] = {
val req = ctx.request
// val cors = CorsSettings.fromJson(ctx.config).getOrElse(CorsSettings()).copy(enabled = true)
val cors = ctx.cachedConfig(internalName)(configReads).getOrElse(NgCorsSettings())

if (req.method == "OPTIONS" && req.headers.get("Access-Control-Request-Method").isDefined) {
// handle cors preflight request
if (cors.legacy.shouldNotPass(req)) {
Expand Down Expand Up @@ -167,10 +167,10 @@ class Cors extends NgRequestTransformer with NgPreRouting {
ctx: NgTransformerErrorContext
)(implicit env: Env, ec: ExecutionContext, mat: Materializer): Future[NgPluginHttpResponse] = {
val req = ctx.request
val cors =
CorsSettings.fromJson(ctx.config).getOrElse(CorsSettings()).copy(enabled = true, excludedPatterns = Seq.empty)
val cors = ctx.cachedConfig(internalName)(configReads).getOrElse(NgCorsSettings())

val corsHeaders = cors
.legacy
.asHeaders(req)
.filter(t => t._1.trim.nonEmpty && t._2.trim.nonEmpty)
.map(v =>
Expand Down

0 comments on commit a7b7fac

Please sign in to comment.