From 9054c696477370f79cb5c8cd4ba5364962e996e6 Mon Sep 17 00:00:00 2001 From: Manfred Zingl Date: Wed, 13 Mar 2024 09:51:14 +0100 Subject: [PATCH] use request.absoluteURI() as fallback --- src/main/scala/com/campudus/tableaux/Starter.scala | 2 +- src/main/scala/com/campudus/tableaux/TableauxConfig.scala | 2 +- .../campudus/tableaux/router/DocumentationRouter.scala | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/scala/com/campudus/tableaux/Starter.scala b/src/main/scala/com/campudus/tableaux/Starter.scala index 7f82b532..3266491c 100644 --- a/src/main/scala/com/campudus/tableaux/Starter.scala +++ b/src/main/scala/com/campudus/tableaux/Starter.scala @@ -53,7 +53,7 @@ class Starter extends ScalaVerticle with LazyLogging { val uploadsDirectory = getStringDefault(config, "uploadsDirectory", Starter.DEFAULT_UPLOADS_DIRECTORY) val authConfig = config.getJsonObject("auth", Json.obj()) val rolePermissionsPath = getStringDefault(config, "rolePermissionsPath", Starter.DEFAULT_ROLE_PERMISSIONS_PATH) - val openApiUrl = getStringDefault(config, "openApiUrl", "") + val openApiUrl = Option(getStringDefault(config, "openApiUrl", null)) val rolePermissions = FileUtils(vertxAccessContainer()).readJsonFile(rolePermissionsPath, Json.emptyObj()) diff --git a/src/main/scala/com/campudus/tableaux/TableauxConfig.scala b/src/main/scala/com/campudus/tableaux/TableauxConfig.scala index 3ab68e02..9603ac70 100644 --- a/src/main/scala/com/campudus/tableaux/TableauxConfig.scala +++ b/src/main/scala/com/campudus/tableaux/TableauxConfig.scala @@ -14,7 +14,7 @@ class TableauxConfig( workingDirectory: String, uploadsDirectory: String, val rolePermissions: JsonObject, - val openApiUrl: String = "" + val openApiUrl: Option[String] = None ) extends VertxAccess { def uploadsDirectoryPath(): Path = { diff --git a/src/main/scala/com/campudus/tableaux/router/DocumentationRouter.scala b/src/main/scala/com/campudus/tableaux/router/DocumentationRouter.scala index a3d1dea6..d0dab1cd 100644 --- a/src/main/scala/com/campudus/tableaux/router/DocumentationRouter.scala +++ b/src/main/scala/com/campudus/tableaux/router/DocumentationRouter.scala @@ -130,10 +130,12 @@ class DocumentationRouter(override val config: TableauxConfig) extends BaseRoute }) val forwardedUrl = request.getHeader("x-forwarded-url") + val openApiUrl = config.openApiUrl - val uri = (forwardedScheme, forwardedHost, forwardedUrl) match { - case (Some(scheme), Some(host), Some(query)) => s"$scheme://$host$query" - case _ => config.openApiUrl + val uri = (forwardedScheme, forwardedHost, forwardedUrl, openApiUrl) match { + case (Some(scheme), Some(host), Some(query), _) => s"$scheme://$host$query" + case (_, _, _, Some(openApiUrl)) => openApiUrl + case _ => request.absoluteURI() } DocUriParser.parse(uri)