Skip to content

Commit

Permalink
fix: fix cors is blocking local development & allows for other domain…
Browse files Browse the repository at this point in the history
…s to access
  • Loading branch information
duruer committed Feb 10, 2025
1 parent 5b622e7 commit 9a7dd6e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Pano/src/main/kotlin/com/panomc/platform/model/Route.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.panomc.platform.model

import com.panomc.platform.Main
import com.panomc.platform.config.ConfigManager
import io.vertx.core.Handler
import io.vertx.core.http.HttpMethod
Expand All @@ -23,7 +24,7 @@ abstract class Route {
abstract fun getHandler(): Handler<RoutingContext>

companion object {
private val allowedHeaders = setOf(
val allowedHeaders = setOf(
"x-requested-with",
"Access-Control-Allow-Origin",
"origin",
Expand All @@ -33,7 +34,7 @@ abstract class Route {
"x-csrf-token"
)

private val allowedMethods = setOf<HttpMethod>(
val allowedMethods = setOf<HttpMethod>(
HttpMethod.GET,
HttpMethod.POST,
HttpMethod.OPTIONS,
Expand All @@ -43,10 +44,13 @@ abstract class Route {
)
}

open fun corsHandler(): Handler<RoutingContext>? = CorsHandler.create(".*.")
.allowCredentials(true)
.allowedHeaders(allowedHeaders)
.allowedMethods(allowedMethods)
open fun corsHandler(): Handler<RoutingContext>? =
if (Main.ENVIRONMENT == Main.Companion.EnvironmentType.DEVELOPMENT)
CorsHandler.create("http://(localhost|127\\.0\\.0\\.1|0\\.0\\.0\\.0)(:[0-9]+)?")
.allowCredentials(false)
.allowedHeaders(allowedHeaders)
.allowedMethods(allowedMethods)
else null

open fun bodyHandler(): Handler<RoutingContext>? = BodyHandler.create()
.setDeleteUploadedFilesOnEnd(true)
Expand Down

0 comments on commit 9a7dd6e

Please sign in to comment.