mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 18:08:25 +00:00
Streamline routing
- put openapi doc behind `api/doc` instead of `app/doc` - don't require `index.html` for the webapp
This commit is contained in:
@ -22,17 +22,18 @@ object RestServer {
|
||||
blocker: Blocker
|
||||
)(implicit T: Timer[F], CS: ContextShift[F]): Stream[F, Nothing] = {
|
||||
|
||||
val templates = TemplateRoutes[F](blocker, cfg)
|
||||
val app = for {
|
||||
restApp <- RestAppImpl.create[F](cfg, connectEC, httpClientEc, blocker)
|
||||
|
||||
httpApp = Router(
|
||||
"/api/info" -> routes.InfoRoutes(),
|
||||
"/api/v1/open/" -> openRoutes(cfg, restApp),
|
||||
"/api/v1/sec/" -> Authenticate(restApp.backend.login, cfg.auth) { token =>
|
||||
securedRoutes(cfg, restApp, token)
|
||||
},
|
||||
"/api/doc" -> templates.doc,
|
||||
"/app/assets" -> WebjarRoutes.appRoutes[F](blocker),
|
||||
"/app" -> TemplateRoutes[F](blocker, cfg)
|
||||
"/app" -> templates.app
|
||||
).orNotFound
|
||||
|
||||
finalHttpApp = Logger.httpApp(logHeaders = false, logBody = false)(httpApp)
|
||||
|
@ -21,7 +21,7 @@ object Flags {
|
||||
cfg.appName,
|
||||
cfg.baseUrl,
|
||||
cfg.backend.signup.mode,
|
||||
s"assets/docspell-webapp/${BuildInfo.version}"
|
||||
s"/app/assets/docspell-webapp/${BuildInfo.version}"
|
||||
)
|
||||
|
||||
implicit val jsonEncoder: Encoder[Flags] =
|
||||
|
@ -21,25 +21,36 @@ object TemplateRoutes {
|
||||
|
||||
val `text/html` = new MediaType("text", "html")
|
||||
|
||||
trait InnerRoutes[F[_]] {
|
||||
def doc: HttpRoutes[F]
|
||||
def app: HttpRoutes[F]
|
||||
}
|
||||
|
||||
def apply[F[_]: Effect](blocker: Blocker, cfg: Config)(
|
||||
implicit C: ContextShift[F]
|
||||
): HttpRoutes[F] = {
|
||||
): InnerRoutes[F] = {
|
||||
val indexTemplate = memo(loadResource("/index.html").flatMap(loadTemplate(_, blocker)))
|
||||
val docTemplate = memo(loadResource("/doc.html").flatMap(loadTemplate(_, blocker)))
|
||||
|
||||
val dsl = new Http4sDsl[F] {}
|
||||
import dsl._
|
||||
HttpRoutes.of[F] {
|
||||
case GET -> Root / "index.html" =>
|
||||
for {
|
||||
templ <- indexTemplate
|
||||
resp <- Ok(IndexData(cfg).render(templ), `Content-Type`(`text/html`))
|
||||
} yield resp
|
||||
case GET -> Root / "doc" =>
|
||||
for {
|
||||
templ <- docTemplate
|
||||
resp <- Ok(DocData().render(templ), `Content-Type`(`text/html`))
|
||||
} yield resp
|
||||
new InnerRoutes[F] {
|
||||
def doc =
|
||||
HttpRoutes.of[F] {
|
||||
case GET -> Root =>
|
||||
for {
|
||||
templ <- docTemplate
|
||||
resp <- Ok(DocData().render(templ), `Content-Type`(`text/html`))
|
||||
} yield resp
|
||||
}
|
||||
def app =
|
||||
HttpRoutes.of[F] {
|
||||
case GET -> _ =>
|
||||
for {
|
||||
templ <- indexTemplate
|
||||
resp <- Ok(IndexData(cfg).render(templ), `Content-Type`(`text/html`))
|
||||
} yield resp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user