Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make non-empty basepath work #1263

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/restapi/src/main/resources/docspell-openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ externalDocs:
url: https://docspell.org

servers:
- url: /api/v1
- url: /andy/api/v1
description: Current host

paths:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,33 @@ object RestServer {
)(
wsB: WebSocketBuilder2[F]
) = {
val basePath = cfg.baseUrl.path.asString
val templates = TemplateRoutes[F](cfg)
val httpApp = 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("/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] =
Expand Down Expand Up @@ -156,7 +159,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),
Expand Down Expand Up @@ -211,7 +214,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)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,6 +30,7 @@ object AttachmentRoutes {

def apply[F[_]: Async](
backend: BackendApp[F],
cfg: Config,
user: AuthToken
): HttpRoutes[F] = {
val dsl = new Http4sDsl[F] {}
Expand Down Expand Up @@ -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" =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -23,6 +24,7 @@ object ShareAttachmentRoutes {

def apply[F[_]: Async](
backend: BackendApp[F],
cfg: Config,
token: ShareToken
): HttpRoutes[F] = {
val dsl = new Http4sDsl[F] {}
Expand All @@ -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" =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand All @@ -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
Expand Down Expand Up @@ -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] =
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion modules/restserver/src/main/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<script>
if('serviceWorker' in navigator) {
navigator.serviceWorker
.register('/sw.js')
.register('/andy/sw.js')
.then(function() { console.log("Service Worker Registered"); });
}
</script>
Expand Down
18 changes: 9 additions & 9 deletions modules/webapp/src/main/elm/Api.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
2 changes: 1 addition & 1 deletion modules/webapp/src/main/elm/App/Update.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/webapp/src/main/elm/Comp/ItemCard.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions modules/webapp/src/main/elm/Comp/ItemDetail/ShowQrCode.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions modules/webapp/src/main/elm/Comp/ItemDetail/SingleAttachment.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 ->
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -346,20 +346,20 @@ 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"
, classList
[ ( "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
Expand Down Expand Up @@ -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"
]
[]
Expand Down