From a235b7db8981a654b460731a7b0a25299f1a8dae Mon Sep 17 00:00:00 2001 From: andy Date: Sat, 1 Jan 2022 13:41:54 +0100 Subject: [PATCH 1/5] Add base_path --- .../main/scala/docspell/joex/JoexServer.scala | 7 +++-- .../docspell/restserver/RestServer.scala | 28 +++++++++-------- .../restserver/routes/AttachmentRoutes.scala | 6 ++-- .../routes/ShareAttachmentRoutes.scala | 6 ++-- .../docspell/restserver/webapp/Flags.scala | 2 +- .../restserver/webapp/TemplateRoutes.scala | 30 +++++++++---------- 6 files changed, 43 insertions(+), 36 deletions(-) diff --git a/modules/joex/src/main/scala/docspell/joex/JoexServer.scala b/modules/joex/src/main/scala/docspell/joex/JoexServer.scala index ef06f730f2..75ed130f43 100644 --- a/modules/joex/src/main/scala/docspell/joex/JoexServer.scala +++ b/modules/joex/src/main/scala/docspell/joex/JoexServer.scala @@ -54,12 +54,13 @@ object JoexServer { joexApp <- JoexAppImpl.create[F](cfg, signal, store, httpClient, pubSub) + val basePath = cfg.baseUrl.path.asString httpApp = Router( - "/internal" -> InternalHeader(settings.internalRouteKey) { + basePath + "/internal" -> InternalHeader(settings.internalRouteKey) { Router("pubsub" -> pubSub.receiveRoute) }, - "/api/info" -> InfoRoutes(cfg), - "/api/v1" -> JoexRoutes(joexApp) + basePath + "/api/info" -> InfoRoutes(cfg), + basePath + "/api/v1" -> JoexRoutes(joexApp) ).orNotFound // With Middlewares in place diff --git a/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala b/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala index aaecc0ddcd..4100bfd31b 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala @@ -104,27 +104,29 @@ object RestServer { )( wsB: WebSocketBuilder2[F] ) = { + val basePath = cfg.baseUrl.path.asString val templates = TemplateRoutes[F](cfg) val httpApp = Router( - "/internal" -> InternalHeader(internSettings.internalRouteKey) { + basePath + "/internal" -> InternalHeader(internSettings.internalRouteKey) { internalRoutes(pubSub) }, - "/api/info" -> routes.InfoRoutes(), - "/api/v1/open/" -> openRoutes(cfg, httpClient, restApp), - "/api/v1/sec/" -> Authenticate(restApp.backend.login, cfg.auth) { token => + basePath + "/api/info" -> routes.InfoRoutes(), + basePath + "/api/v1/open/" -> openRoutes(cfg, httpClient, restApp), + basePath + "/api/v1/sec/" -> Authenticate(restApp.backend.login, cfg.auth) { token => securedRoutes(cfg, restApp, wsB, topic, token) }, - "/api/v1/admin" -> AdminAuth(cfg.adminEndpoint) { + basePath + "/api/v1/admin" -> AdminAuth(cfg.adminEndpoint) { adminRoutes(cfg, restApp) }, - "/api/v1/share" -> ShareAuth(restApp.backend.share, cfg.auth) { token => + basePath + "/api/v1/share" -> ShareAuth(restApp.backend.share, cfg.auth) { token => shareRoutes(cfg, restApp, token) }, - "/api/doc" -> templates.doc, - "/app/assets" -> EnvMiddleware(WebjarRoutes.appRoutes[F]), - "/app" -> EnvMiddleware(templates.app), - "/sw.js" -> EnvMiddleware(templates.serviceWorker), - "/" -> redirectTo("/app") + basePath + "/api/doc" -> templates.doc, + basePath + "/app/assets" -> EnvMiddleware(WebjarRoutes.appRoutes[F]), + basePath + "/app" -> EnvMiddleware(templates.app), + basePath + "/sw.js" -> EnvMiddleware(templates.serviceWorker), + basePath + "/" -> redirectTo(basePath + "/app"), + "/" -> redirectTo(basePath + "/app") ).orNotFound Logger.httpApp(logHeaders = false, logBody = false)(httpApp) @@ -156,7 +158,7 @@ object RestServer { "queue" -> JobQueueRoutes(restApp.backend, token), "item" -> ItemRoutes(cfg, restApp.backend, token), "items" -> ItemMultiRoutes(cfg, restApp.backend, token), - "attachment" -> AttachmentRoutes(restApp.backend, token), + "attachment" -> AttachmentRoutes(restApp.backend, cfg, token), "attachments" -> AttachmentMultiRoutes(restApp.backend, token), "upload" -> UploadRoutes.secured(restApp.backend, cfg, token), "checkfile" -> CheckFileRoutes.secured(restApp.backend, token), @@ -211,7 +213,7 @@ object RestServer { ): HttpRoutes[F] = Router( "search" -> ShareSearchRoutes(restApp.backend, cfg, token), - "attachment" -> ShareAttachmentRoutes(restApp.backend, token), + "attachment" -> ShareAttachmentRoutes(restApp.backend, cfg, token), "item" -> ShareItemRoutes(restApp.backend, token) ) diff --git a/modules/restserver/src/main/scala/docspell/restserver/routes/AttachmentRoutes.scala b/modules/restserver/src/main/scala/docspell/restserver/routes/AttachmentRoutes.scala index a7bc4b82c5..ffefb4abaa 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/routes/AttachmentRoutes.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/routes/AttachmentRoutes.scala @@ -15,6 +15,7 @@ import docspell.backend.ops._ import docspell.common.Ident import docspell.common.MakePreviewArgs import docspell.restapi.model._ +import docspell.restserver.Config import docspell.restserver.conv.Conversions import docspell.restserver.http4s.BinaryUtil import docspell.restserver.webapp.Webjars @@ -29,6 +30,7 @@ object AttachmentRoutes { def apply[F[_]: Async]( backend: BackendApp[F], + cfg: Config, user: AuthToken ): HttpRoutes[F] = { val dsl = new Http4sDsl[F] {} @@ -132,8 +134,8 @@ object AttachmentRoutes { case GET -> Root / Ident(id) / "view" => // this route exists to provide a stable url // it redirects currently to viewerjs - val attachUrl = s"/api/v1/sec/attachment/${id.id}" - val path = s"/app/assets${Webjars.viewerjs}/index.html#$attachUrl" + val attachUrl = s"${cfg.baseUrl.path.asString}/api/v1/sec/attachment/${id.id}" + val path = s"${cfg.baseUrl.path.asString}/app/assets${Webjars.viewerjs}/index.html#$attachUrl" SeeOther(Location(Uri(path = Uri.Path.unsafeFromString(path)))) case GET -> Root / Ident(id) / "meta" => diff --git a/modules/restserver/src/main/scala/docspell/restserver/routes/ShareAttachmentRoutes.scala b/modules/restserver/src/main/scala/docspell/restserver/routes/ShareAttachmentRoutes.scala index b93a138136..28dbb9e954 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/routes/ShareAttachmentRoutes.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/routes/ShareAttachmentRoutes.scala @@ -12,6 +12,7 @@ import cats.implicits._ import docspell.backend.BackendApp import docspell.backend.auth.ShareToken import docspell.common._ +import docspell.restserver.Config import docspell.restserver.http4s.BinaryUtil import docspell.restserver.webapp.Webjars @@ -23,6 +24,7 @@ object ShareAttachmentRoutes { def apply[F[_]: Async]( backend: BackendApp[F], + cfg: Config, token: ShareToken ): HttpRoutes[F] = { val dsl = new Http4sDsl[F] {} @@ -44,8 +46,8 @@ object ShareAttachmentRoutes { case GET -> Root / Ident(id) / "view" => // this route exists to provide a stable url // it redirects currently to viewerjs - val attachUrl = s"/api/v1/share/attachment/${id.id}" - val path = s"/app/assets${Webjars.viewerjs}/index.html#$attachUrl" + val attachUrl = s"${cfg.baseUrl.path.asString}/api/v1/share/attachment/${id.id}" + val path = s"${cfg.baseUrl.path.asString}/app/assets${Webjars.viewerjs}/index.html#$attachUrl" SeeOther(Location(Uri(path = Uri.Path.unsafeFromString(path)))) case req @ GET -> Root / Ident(id) / "preview" => diff --git a/modules/restserver/src/main/scala/docspell/restserver/webapp/Flags.scala b/modules/restserver/src/main/scala/docspell/restserver/webapp/Flags.scala index 393b2be896..44beaf49cc 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/webapp/Flags.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/webapp/Flags.scala @@ -35,7 +35,7 @@ object Flags { cfg.appName, getBaseUrl(cfg), cfg.backend.signup.mode, - s"/app/assets/docspell-webapp/${BuildInfo.version}", + s"${cfg.baseUrl.path.asString}/app/assets/docspell-webapp/${BuildInfo.version}", cfg.integrationEndpoint.enabled, cfg.fullTextSearch.enabled, cfg.maxItemPageSize, diff --git a/modules/restserver/src/main/scala/docspell/restserver/webapp/TemplateRoutes.scala b/modules/restserver/src/main/scala/docspell/restserver/webapp/TemplateRoutes.scala index 43ed9a5baa..e60fa97f1c 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/webapp/TemplateRoutes.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/webapp/TemplateRoutes.scala @@ -39,10 +39,10 @@ object TemplateRoutes { def apply[F[_]: Async](cfg: Config): InnerRoutes[F] = { val indexTemplate = memo( - loadResource("/index.html").flatMap(loadTemplate(_)) + loadResource(s"/index.html").flatMap(loadTemplate(_)) ) - val docTemplate = memo(loadResource("/doc.html").flatMap(loadTemplate(_))) - val swTemplate = memo(loadResource("/sw.js").flatMap(loadTemplate(_))) + val docTemplate = memo(loadResource(s"/doc.html").flatMap(loadTemplate(_))) + val swTemplate = memo(loadResource(s"/sw.js").flatMap(loadTemplate(_))) val dsl = new Http4sDsl[F] {} import dsl._ @@ -52,7 +52,7 @@ object TemplateRoutes { for { templ <- docTemplate resp <- Ok( - DocData().render(templ), + DocData(cfg).render(templ), `Content-Type`(textHtml, Charset.`UTF-8`) ) } yield resp @@ -108,10 +108,10 @@ object TemplateRoutes { case class DocData(swaggerRoot: String, openapiSpec: String) object DocData { - def apply(): DocData = + def apply(cfg: Config): DocData = DocData( - "/app/assets" + Webjars.swaggerui, - s"/app/assets/${BuildInfo.name}/${BuildInfo.version}/docspell-openapi.yml" + cfg.baseUrl.path.asString + "/app/assets" + Webjars.swaggerui, + s"${cfg.baseUrl.path.asString}/app/assets/${BuildInfo.name}/${BuildInfo.version}/docspell-openapi.yml" ) implicit def yamuscaValueConverter: ValueConverter[DocData] = @@ -133,19 +133,19 @@ object TemplateRoutes { def apply(cfg: Config): IndexData = IndexData( Flags(cfg, uiVersion), - chooseUi, + chooseUi(cfg), Seq( - "/app/assets" + Webjars.clipboardjs + "/clipboard.min.js", - s"/app/assets/docspell-webapp/${BuildInfo.version}/docspell-app.js", - s"/app/assets/docspell-webapp/${BuildInfo.version}/docspell-query-opt.js" + cfg.baseUrl.path.asString + "/app/assets" + Webjars.clipboardjs + "/clipboard.min.js", + s"${cfg.baseUrl.path.asString}/app/assets/docspell-webapp/${BuildInfo.version}/docspell-app.js", + s"${cfg.baseUrl.path.asString}/app/assets/docspell-webapp/${BuildInfo.version}/docspell-query-opt.js" ), - s"/app/assets/docspell-webapp/${BuildInfo.version}/favicon", - s"/app/assets/docspell-webapp/${BuildInfo.version}/docspell.js", + s"${cfg.baseUrl.path.asString}/app/assets/docspell-webapp/${BuildInfo.version}/favicon", + s"${cfg.baseUrl.path.asString}/app/assets/docspell-webapp/${BuildInfo.version}/docspell.js", Flags(cfg, uiVersion).asJson.spaces2 ) - private def chooseUi: Seq[String] = - Seq(s"/app/assets/docspell-webapp/${BuildInfo.version}/css/styles.css") + private def chooseUi(cfg: Config): Seq[String] = + Seq(s"${cfg.baseUrl.path.asString}/app/assets/docspell-webapp/${BuildInfo.version}/css/styles.css") implicit def yamuscaValueConverter: ValueConverter[IndexData] = ValueConverter.deriveConverter[IndexData] From 5eee5ec2af589a0c486888a00bb3a7ac8ae0397d Mon Sep 17 00:00:00 2001 From: andy Date: Sat, 1 Jan 2022 13:44:08 +0100 Subject: [PATCH 2/5] Preliminary change check for /app paths, should contain base_path --- modules/webapp/src/main/elm/App/Update.elm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/webapp/src/main/elm/App/Update.elm b/modules/webapp/src/main/elm/App/Update.elm index 20e513594f..0ae3b98216 100644 --- a/modules/webapp/src/main/elm/App/Update.elm +++ b/modules/webapp/src/main/elm/App/Update.elm @@ -232,7 +232,7 @@ updateWithSub msg model = NavRequest req -> case req of Internal url -> - if String.startsWith "/app" url.path then + if String.contains "/app" url.path then let isCurrent = Page.fromUrl url From a7ec3709f7173e3afa0a52a0c300c9b6072e60a0 Mon Sep 17 00:00:00 2001 From: andy Date: Sat, 1 Jan 2022 13:44:49 +0100 Subject: [PATCH 3/5] Preliminary hardcode base_path to "/andy" --- .../restserver/src/main/templates/index.html | 2 +- modules/webapp/src/main/elm/Comp/ItemCard.elm | 4 +-- modules/webapp/src/main/elm/Page.elm | 28 ++++++++++--------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/modules/restserver/src/main/templates/index.html b/modules/restserver/src/main/templates/index.html index a94abf75cf..3a07d8226f 100644 --- a/modules/restserver/src/main/templates/index.html +++ b/modules/restserver/src/main/templates/index.html @@ -66,7 +66,7 @@ diff --git a/modules/webapp/src/main/elm/Comp/ItemCard.elm b/modules/webapp/src/main/elm/Comp/ItemCard.elm index e240913105..4217fe05ad 100644 --- a/modules/webapp/src/main/elm/Comp/ItemCard.elm +++ b/modules/webapp/src/main/elm/Comp/ItemCard.elm @@ -202,7 +202,7 @@ viewRow texts cfg settings flags model item = attachUrl = Maybe.map mkAttachUrl mainAttach - |> Maybe.withDefault "/api/v1/sec/attachment/none" + |> Maybe.withDefault "/andy/api/v1/sec/attachment/none" fieldHidden f = Data.UiSettings.fieldHidden settings f @@ -844,7 +844,7 @@ previewMenu2 texts settings flags cfg model item mainAttach = attachUrl = Maybe.map mkAttachUrl mainAttach - |> Maybe.withDefault "/api/v1/sec/attachment/none" + |> Maybe.withDefault "/andy/api/v1/sec/attachment/none" dueDate = IT.render IT.dueDateShort (templateCtx texts) item diff --git a/modules/webapp/src/main/elm/Page.elm b/modules/webapp/src/main/elm/Page.elm index a14e529513..115be547d7 100644 --- a/modules/webapp/src/main/elm/Page.elm +++ b/modules/webapp/src/main/elm/Page.elm @@ -27,6 +27,7 @@ module Page exposing ) import Browser.Navigation as Nav +import Data.Flags exposing (Flags) import Html exposing (Attribute) import Html.Attributes as Attr import Url exposing (Url) @@ -227,50 +228,51 @@ pageToString : Page -> String pageToString page = case page of HomePage -> - "/app/home" + "/andy" ++ "/app/home" LoginPage data -> case data.referrer of Just (LoginPage _) -> - "/app/login" + "/andy" ++ "/app/login" Just p -> - "/app/login?r=" ++ pageToString p + String.concat ["/andy", "/app/login?r=", pageToString p] Nothing -> - "/app/login" + "/andy" ++ "/app/login" ManageDataPage -> - "/app/managedata" + "/andy" ++ "/app/managedata" CollectiveSettingPage -> - "/app/csettings" + "/andy" ++ "/app/csettings" UserSettingPage -> - "/app/usettings" + "/andy" ++ "/app/usettings" QueuePage -> - "/app/queue" + "/andy" ++ "/app/queue" RegisterPage -> - "/app/register" + "/andy" ++ "/app/register" UploadPage sourceId -> Maybe.map (\id -> "/" ++ id) sourceId |> Maybe.withDefault "" + |> (++) "/andy" |> (++) "/app/upload" NewInvitePage -> - "/app/newinvite" + "/andy" ++ "/app/newinvite" ItemDetailPage id -> - "/app/item/" ++ id + "/andy" ++ "/app/item/" ++ id SharePage id -> - "/app/share/" ++ id + "/andy" ++ "/app/share/" ++ id ShareDetailPage shareId itemId -> - "/app/share/" ++ shareId ++ "/" ++ itemId + "/andy" ++ "/app/share/" ++ shareId ++ "/" ++ itemId pageFromString : String -> Maybe Page From 8296d37324a16548f095526c3f31692f24a47cc4 Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 3 Jan 2022 21:28:46 +0100 Subject: [PATCH 4/5] Preliminary hardcode base_path to "/andy" --- modules/restapi/src/main/resources/docspell-openapi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/restapi/src/main/resources/docspell-openapi.yml b/modules/restapi/src/main/resources/docspell-openapi.yml index 6c8f55308b..30ab5e448f 100644 --- a/modules/restapi/src/main/resources/docspell-openapi.yml +++ b/modules/restapi/src/main/resources/docspell-openapi.yml @@ -24,7 +24,7 @@ externalDocs: url: https://docspell.org servers: - - url: /api/v1 + - url: /andy/api/v1 description: Current host paths: From 074bbe13ea1289940c69dc9885354e71bce62f5e Mon Sep 17 00:00:00 2001 From: eikek Date: Sat, 8 Jan 2022 13:34:32 +0100 Subject: [PATCH 5/5] Some more trial and error for having a context path - The JoexServer is not affected by this, it is only used internally and not exposed, so I would simply skip this - Sadly, the javascript file has to be fixed as well that creates a websocket connection. Can be fixed by making it a template or passing the contextPath as argument - Need to fix the cookie path (I didn't make sure to fix all) - Another problem is obtaining the base url. Currently, if the config is set to "localhost" we simply clobber the url together from the request and here we don't know the base path and simply set the empty path. I now fixed this also to be "/andy", but we need to get the configured basePath from the config - Most changes in Elm was fixing the URL to preview images and files --- .../main/scala/docspell/joex/JoexServer.scala | 7 ++- .../docspell/restserver/RestServer.scala | 43 ++++++++++--------- .../restserver/http4s/ClientRequestInfo.scala | 2 +- modules/webapp/src/main/elm/Api.elm | 18 ++++---- .../main/elm/Comp/ItemDetail/ShowQrCode.elm | 4 +- .../elm/Comp/ItemDetail/SingleAttachment.elm | 24 +++++------ .../webapp/src/main/elm/Comp/ItemMerge.elm | 12 +++--- modules/webapp/src/main/elm/Main.elm | 1 - modules/webapp/src/main/elm/Page.elm | 33 ++++++++------ .../webapp/src/main/elm/Page/Home/View2.elm | 16 +++---- modules/webapp/src/main/webjar/docspell.js | 2 +- 11 files changed, 82 insertions(+), 80 deletions(-) diff --git a/modules/joex/src/main/scala/docspell/joex/JoexServer.scala b/modules/joex/src/main/scala/docspell/joex/JoexServer.scala index 75ed130f43..ef06f730f2 100644 --- a/modules/joex/src/main/scala/docspell/joex/JoexServer.scala +++ b/modules/joex/src/main/scala/docspell/joex/JoexServer.scala @@ -54,13 +54,12 @@ object JoexServer { joexApp <- JoexAppImpl.create[F](cfg, signal, store, httpClient, pubSub) - val basePath = cfg.baseUrl.path.asString httpApp = Router( - basePath + "/internal" -> InternalHeader(settings.internalRouteKey) { + "/internal" -> InternalHeader(settings.internalRouteKey) { Router("pubsub" -> pubSub.receiveRoute) }, - basePath + "/api/info" -> InfoRoutes(cfg), - basePath + "/api/v1" -> JoexRoutes(joexApp) + "/api/info" -> InfoRoutes(cfg), + "/api/v1" -> JoexRoutes(joexApp) ).orNotFound // With Middlewares in place diff --git a/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala b/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala index 4100bfd31b..69e20a75ed 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala @@ -107,29 +107,30 @@ object RestServer { val basePath = cfg.baseUrl.path.asString val templates = TemplateRoutes[F](cfg) val httpApp = Router( - basePath + "/internal" -> InternalHeader(internSettings.internalRouteKey) { - internalRoutes(pubSub) - }, - basePath + "/api/info" -> routes.InfoRoutes(), - basePath + "/api/v1/open/" -> openRoutes(cfg, httpClient, restApp), - basePath + "/api/v1/sec/" -> Authenticate(restApp.backend.login, cfg.auth) { token => - securedRoutes(cfg, restApp, wsB, topic, token) - }, - basePath + "/api/v1/admin" -> AdminAuth(cfg.adminEndpoint) { - adminRoutes(cfg, restApp) - }, - basePath + "/api/v1/share" -> ShareAuth(restApp.backend.share, cfg.auth) { token => - shareRoutes(cfg, restApp, token) - }, - basePath + "/api/doc" -> templates.doc, - basePath + "/app/assets" -> EnvMiddleware(WebjarRoutes.appRoutes[F]), - basePath + "/app" -> EnvMiddleware(templates.app), - basePath + "/sw.js" -> EnvMiddleware(templates.serviceWorker), - basePath + "/" -> redirectTo(basePath + "/app"), - "/" -> redirectTo(basePath + "/app") + basePath -> Router( + "internal" -> InternalHeader(internSettings.internalRouteKey) { + internalRoutes(pubSub) + }, + "api/info" -> routes.InfoRoutes(), + "api/v1/open/" -> openRoutes(cfg, httpClient, restApp), + "api/v1/sec/" -> Authenticate(restApp.backend.login, cfg.auth) { token => + securedRoutes(cfg, restApp, wsB, topic, token) + }, + "api/v1/admin" -> AdminAuth(cfg.adminEndpoint) { + adminRoutes(cfg, restApp) + }, + "api/v1/share" -> ShareAuth(restApp.backend.share, cfg.auth) { token => + shareRoutes(cfg, restApp, token) + }, + "api/doc" -> templates.doc, + "app/assets" -> EnvMiddleware(WebjarRoutes.appRoutes[F]), + "app" -> EnvMiddleware(templates.app), + "sw.js" -> EnvMiddleware(templates.serviceWorker), + "" -> redirectTo(basePath + "/app") + ) ).orNotFound - Logger.httpApp(logHeaders = false, logBody = false)(httpApp) + Logger.httpApp(logHeaders = true, logBody = false)(httpApp) } def internalRoutes[F[_]: Async](pubSub: NaivePubSub[F]): HttpRoutes[F] = diff --git a/modules/restserver/src/main/scala/docspell/restserver/http4s/ClientRequestInfo.scala b/modules/restserver/src/main/scala/docspell/restserver/http4s/ClientRequestInfo.scala index 8d962b78cf..cdde28b036 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/http4s/ClientRequestInfo.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/http4s/ClientRequestInfo.scala @@ -29,7 +29,7 @@ object ClientRequestInfo { host <- getHostname(req) port = xForwardedPort(req).getOrElse(serverPort) hostPort = if (port == 80 || port == 443) host else s"$host:$port" - } yield LenientUri(scheme, Some(hostPort), LenientUri.EmptyPath, None, None) + } yield LenientUri(scheme, Some(hostPort), LenientUri.NonEmptyPath(NonEmptyList.of("andy")), None, None) def getHostname[F[_]](req: Request[F]): Option[String] = xForwardedHost(req) diff --git a/modules/webapp/src/main/elm/Api.elm b/modules/webapp/src/main/elm/Api.elm index 1d719f5cbe..493c23a71d 100644 --- a/modules/webapp/src/main/elm/Api.elm +++ b/modules/webapp/src/main/elm/Api.elm @@ -1940,19 +1940,19 @@ reprocessItem flags itemId attachIds receive = } -attachmentPreviewURL : String -> String -attachmentPreviewURL id = - "/api/v1/sec/attachment/" ++ id ++ "/preview?withFallback=true" +attachmentPreviewURL : Flags -> String -> String +attachmentPreviewURL flags id = + flags.config.baseUrl ++ "/api/v1/sec/attachment/" ++ id ++ "/preview?withFallback=true" -itemBasePreviewURL : String -> String -itemBasePreviewURL itemId = - "/api/v1/sec/item/" ++ itemId ++ "/preview?withFallback=true" +itemBasePreviewURL : Flags -> String -> String +itemBasePreviewURL flags itemId = + flags.config.baseUrl ++ "/api/v1/sec/item/" ++ itemId ++ "/preview?withFallback=true" -fileURL : String -> String -fileURL attachId = - "/api/v1/sec/attachment/" ++ attachId +fileURL : Flags -> String -> String +fileURL flags attachId = + flags.config.baseUrl ++ "/api/v1/sec/attachment/" ++ attachId setAttachmentName : diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/ShowQrCode.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/ShowQrCode.elm index a6e3a96f25..0fc0c92c7c 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/ShowQrCode.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/ShowQrCode.elm @@ -8,13 +8,11 @@ module Comp.ItemDetail.ShowQrCode exposing (UrlId(..), qrCodeElementId, view, view1) import Api -import Comp.Basic as B import Comp.ItemDetail.Model exposing (Model, Msg(..), isShowQrAttach, isShowQrItem) import Comp.MenuBar as MB import Data.Flags exposing (Flags) import Html exposing (..) import Html.Attributes exposing (..) -import Html.Events exposing (onClick) import QRCode import Styles as S import Svg.Attributes as SvgA @@ -44,7 +42,7 @@ view1 flags classes urlId = docUrl = case urlId of Attach str -> - flags.config.baseUrl ++ Api.fileURL str + flags.config.baseUrl ++ Api.fileURL flags str Item str -> flags.config.baseUrl ++ "/app/item/" ++ str diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/SingleAttachment.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/SingleAttachment.elm index 7c8bd0fb02..786668f27c 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/SingleAttachment.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/SingleAttachment.elm @@ -42,7 +42,7 @@ view : Texts -> Flags -> UiSettings -> Model -> Int -> Attachment -> Html Msg view texts flags settings model pos attach = let fileUrl = - Api.fileURL attach.id + Api.fileURL flags attach.id in div [ class "flex flex-col md:relative h-full mb-2" @@ -55,10 +55,10 @@ view texts flags settings model pos attach = [ class "flex flex-row px-2 py-2 text-sm" , class S.border ] - [ attachHeader texts settings model pos attach + [ attachHeader texts flags settings model pos attach ] , editAttachmentName model attach - , attachmentSelect texts model pos attach + , attachmentSelect texts flags model pos attach , if isAttachMetaOpen model attach.id then case Dict.get attach.id model.attachMeta of Just am -> @@ -110,14 +110,14 @@ view texts flags settings model pos attach = - native view -} -attachHeader : Texts -> UiSettings -> Model -> Int -> Attachment -> Html Msg -attachHeader texts settings model _ attach = +attachHeader : Texts -> Flags -> UiSettings -> Model -> Int -> Attachment -> Html Msg +attachHeader texts flags _ model _ attach = let attachName = Maybe.withDefault texts.noName attach.name fileUrl = - Api.fileURL attach.id + Api.fileURL flags attach.id hasArchive = List.map .id model.item.archives @@ -346,8 +346,8 @@ editAttachmentName model attach = span [ class "hidden" ] [] -attachmentSelect : Texts -> Model -> Int -> Attachment -> Html Msg -attachmentSelect texts model _ _ = +attachmentSelect : Texts -> Flags -> Model -> Int -> Attachment -> Html Msg +attachmentSelect texts flags model _ _ = div [ class "flex flex-row border-l border-r px-2 py-2 dark:border-slate-600 " , class "overflow-x-auto overflow-y-none" @@ -355,11 +355,11 @@ attachmentSelect texts model _ _ = [ ( "hidden", not model.attachMenuOpen ) ] ] - (List.indexedMap (menuItem texts model) model.item.attachments) + (List.indexedMap (menuItem texts flags model) model.item.attachments) -menuItem : Texts -> Model -> Int -> Attachment -> Html Msg -menuItem texts model pos attach = +menuItem : Texts -> Flags -> Model -> Int -> Attachment -> Html Msg +menuItem texts flags model pos attach = let highlight = let @@ -427,7 +427,7 @@ menuItem texts model pos attach = ] , div [ class "flex-grow" ] [ img - [ src (Api.attachmentPreviewURL attach.id) + [ src (Api.attachmentPreviewURL flags attach.id) , class "block w-20 mx-auto" ] [] diff --git a/modules/webapp/src/main/elm/Comp/ItemMerge.elm b/modules/webapp/src/main/elm/Comp/ItemMerge.elm index 03b52e8edd..936d56b5aa 100644 --- a/modules/webapp/src/main/elm/Comp/ItemMerge.elm +++ b/modules/webapp/src/main/elm/Comp/ItemMerge.elm @@ -229,8 +229,8 @@ flatten list = --- View -view : Texts -> UiSettings -> Model -> Html Msg -view texts settings model = +view : Texts -> Flags -> UiSettings -> Model -> Html Msg +view texts flags settings model = div [ class "px-2 mb-4" ] [ h1 [ class S.header1 ] [ text texts.title @@ -275,15 +275,15 @@ view texts settings model = } , renderFormState texts model , div [ class "flex-col px-2" ] - (List.indexedMap (itemCard texts settings model) model.items) + (List.indexedMap (itemCard texts flags settings model) model.items) ] -itemCard : Texts -> UiSettings -> Model -> Int -> ItemLight -> Html Msg -itemCard texts settings model index item = +itemCard : Texts -> Flags -> UiSettings -> Model -> Int -> ItemLight -> Html Msg +itemCard texts flags settings model index item = let previewUrl = - Api.itemBasePreviewURL item.id + Api.itemBasePreviewURL flags item.id fieldHidden f = Data.UiSettings.fieldHidden settings f diff --git a/modules/webapp/src/main/elm/Main.elm b/modules/webapp/src/main/elm/Main.elm index 3569ad5c95..be94b7fff8 100644 --- a/modules/webapp/src/main/elm/Main.elm +++ b/modules/webapp/src/main/elm/Main.elm @@ -14,7 +14,6 @@ import App.View2 import Browser exposing (Document) import Browser.Navigation exposing (Key) import Data.Flags exposing (Flags) -import Data.NotificationChannel import Data.UiSettings import Html exposing (..) import Html.Attributes exposing (..) diff --git a/modules/webapp/src/main/elm/Page.elm b/modules/webapp/src/main/elm/Page.elm index 115be547d7..9fb8cc45c7 100644 --- a/modules/webapp/src/main/elm/Page.elm +++ b/modules/webapp/src/main/elm/Page.elm @@ -236,7 +236,7 @@ pageToString page = "/andy" ++ "/app/login" Just p -> - String.concat ["/andy", "/app/login?r=", pageToString p] + String.concat [ "/andy", "/app/login?r=", pageToString p ] Nothing -> "/andy" ++ "/app/login" @@ -306,6 +306,11 @@ goto page = Nav.load (pageToString page) +basePath : String +basePath = + "andy" + + pathPrefix : String pathPrefix = "app" @@ -317,21 +322,21 @@ parser = [ Parser.map HomePage (oneOf [ Parser.top - , s pathPrefix s "home" + , s basePath s pathPrefix s "home" ] ) - , Parser.map LoginPage (s pathPrefix s "login" loginPageParser) - , Parser.map ManageDataPage (s pathPrefix s "managedata") - , Parser.map CollectiveSettingPage (s pathPrefix s "csettings") - , Parser.map UserSettingPage (s pathPrefix s "usettings") - , Parser.map QueuePage (s pathPrefix s "queue") - , Parser.map RegisterPage (s pathPrefix s "register") - , Parser.map (\s -> UploadPage (Just s)) (s pathPrefix s "upload" string) - , Parser.map (UploadPage Nothing) (s pathPrefix s "upload") - , Parser.map NewInvitePage (s pathPrefix s "newinvite") - , Parser.map ItemDetailPage (s pathPrefix s "item" string) - , Parser.map ShareDetailPage (s pathPrefix s "share" string string) - , Parser.map SharePage (s pathPrefix s "share" string) + , Parser.map LoginPage (s basePath s pathPrefix s "login" loginPageParser) + , Parser.map ManageDataPage (s basePath s pathPrefix s "managedata") + , Parser.map CollectiveSettingPage (s basePath s pathPrefix s "csettings") + , Parser.map UserSettingPage (s basePath s pathPrefix s "usettings") + , Parser.map QueuePage (s basePath s pathPrefix s "queue") + , Parser.map RegisterPage (s basePath s pathPrefix s "register") + , Parser.map (\s -> UploadPage (Just s)) (s basePath s pathPrefix s "upload" string) + , Parser.map (UploadPage Nothing) (s basePath s pathPrefix s "upload") + , Parser.map NewInvitePage (s basePath s pathPrefix s "newinvite") + , Parser.map ItemDetailPage (s basePath s pathPrefix s "item" string) + , Parser.map ShareDetailPage (s basePath s pathPrefix s "share" string string) + , Parser.map SharePage (s basePath s pathPrefix s "share" string) ] diff --git a/modules/webapp/src/main/elm/Page/Home/View2.elm b/modules/webapp/src/main/elm/Page/Home/View2.elm index 3f4bf2b139..3b4984747c 100644 --- a/modules/webapp/src/main/elm/Page/Home/View2.elm +++ b/modules/webapp/src/main/elm/Page/Home/View2.elm @@ -74,7 +74,7 @@ mainView texts flags settings model = MergeSelected -> Just [ div [ class "sm:relative mb-2" ] - (itemMergeView texts settings svm) + (itemMergeView texts flags settings svm) ] PublishSelected -> @@ -113,15 +113,15 @@ itemPublishView texts settings flags svm = ] -itemMergeView : Texts -> UiSettings -> SelectViewModel -> List (Html Msg) -itemMergeView texts settings svm = +itemMergeView : Texts -> Flags -> UiSettings -> SelectViewModel -> List (Html Msg) +itemMergeView texts flags settings svm = [ Html.map MergeItemsMsg - (Comp.ItemMerge.view texts.itemMerge settings svm.mergeModel) + (Comp.ItemMerge.view texts.itemMerge flags settings svm.mergeModel) ] publishResults : Texts -> UiSettings -> Flags -> Model -> Comp.PublishItems.Model -> List (Html Msg) -publishResults texts settings flags model pm = +publishResults texts settings flags _ pm = [ Html.map PublishViewMsg (Comp.PublishItems.view texts.publishItems settings flags pm) ] @@ -524,17 +524,17 @@ itemCardList : Texts -> Flags -> UiSettings -> Model -> List (Html Msg) itemCardList texts flags settings model = let previewUrl attach = - Api.attachmentPreviewURL attach.id + Api.attachmentPreviewURL flags attach.id previewUrlFallback item = - Api.itemBasePreviewURL item.id + Api.itemBasePreviewURL flags item.id viewCfg sel = { current = model.scrollToCard , selection = sel , previewUrl = previewUrl , previewUrlFallback = previewUrlFallback - , attachUrl = .id >> Api.fileURL + , attachUrl = .id >> Api.fileURL flags , detailPage = .id >> ItemDetailPage , arrange = settings.itemSearchArrange , showGroups = settings.itemSearchShowGroups diff --git a/modules/webapp/src/main/webjar/docspell.js b/modules/webapp/src/main/webjar/docspell.js index 4b32212e76..8ca180b407 100644 --- a/modules/webapp/src/main/webjar/docspell.js +++ b/modules/webapp/src/main/webjar/docspell.js @@ -153,7 +153,7 @@ function closeWS() { function initWS() { closeWS(); var protocol = (window.location.protocol === 'https:') ? 'wss:' : 'ws:'; - var url = protocol + '//' + window.location.host + '/api/v1/sec/ws'; + var url = protocol + '//' + window.location.host + '/andy/api/v1/sec/ws'; console.log("Initialize websocket at " + url); dsWebSocket = new WebSocket(url); dsWebSocket.addEventListener("message", function(event) {