diff --git a/shared/src/commonMain/kotlin/com/bricks/mp/core/WebBricksRequestContext.kt b/shared/src/commonMain/kotlin/com/bricks/mp/core/WebBricksRequestContext.kt index 5aa6df1..045e5ae 100644 --- a/shared/src/commonMain/kotlin/com/bricks/mp/core/WebBricksRequestContext.kt +++ b/shared/src/commonMain/kotlin/com/bricks/mp/core/WebBricksRequestContext.kt @@ -54,9 +54,21 @@ fun withWebBricksRequestContext( * Detect URLs that need WebBricks backend context (_webbricks_=1). * Covers both direct .ui/.dspy paths and index fallback paths that the * server resolves to .ui files (e.g. "/" → index.ui, "/public" → index.ui). + * + * Handles both full URLs (http://host:port/public) and path-only strings (/public). */ fun String.isWebBricksBackendResource(): Boolean { - val path = substringBefore('?').substringBefore('#') + val withoutQuery = substringBefore('?').substringBefore('#') + + // Extract path component: strip scheme+host for full URLs, keep as-is for paths + val path = if (withoutQuery.contains("://")) { + // Full URL: find first '/' after "://" + val afterScheme = withoutQuery.substringAfter("://") + "/" + afterScheme.substringAfter('/', missingDelimiterValue = "") + } else { + withoutQuery + } + val normalized = path.trimEnd('/') // Direct .ui/.dspy resource