Merge pull request #243 from eikek/build-fixes

Build fixes
This commit is contained in:
mergify[bot] 2020-09-02 23:39:31 +00:00 committed by GitHub
commit 81eba67c3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 35 deletions

View File

@ -59,6 +59,7 @@ lazy val noPublish = Seq(
val elmSettings = Seq( val elmSettings = Seq(
elmCompileMode := ElmCompileMode.Debug, elmCompileMode := ElmCompileMode.Debug,
Compile / resourceGenerators += Def.task { Compile / resourceGenerators += Def.task {
openapiCodegen.value
compileElm( compileElm(
streams.value.log, streams.value.log,
(Compile / baseDirectory).value, (Compile / baseDirectory).value,
@ -565,6 +566,18 @@ val root = project
// --- Helpers // --- Helpers
def copyWithGZ(src: File, target: File): Seq[File] = {
val gzipFilter = "*.html" || "*.css" || "*.js"
IO.copy(Seq(src -> target))
if (gzipFilter.accept(src)) {
val gz = file(target.toString + ".gz")
IO.gzip(src, gz)
Seq(target, gz)
} else {
Seq(target)
}
}
def copyWebjarResources( def copyWebjarResources(
src: Seq[File], src: Seq[File],
base: File, base: File,
@ -577,18 +590,16 @@ def copyWebjarResources(
src.flatMap { dir => src.flatMap { dir =>
if (dir.isDirectory) { if (dir.isDirectory) {
val files = (dir ** "*").filter(_.isFile).get.pair(Path.relativeTo(dir)) val files = (dir ** "*").filter(_.isFile).get.pair(Path.relativeTo(dir))
files.map { files.flatMap {
case (f, name) => case (f, name) =>
val target = targetDir / name val target = targetDir / name
IO.createDirectories(Seq(target.getParentFile)) IO.createDirectories(Seq(target.getParentFile))
IO.copy(Seq(f -> target)) copyWithGZ(f, target)
target
} }
} else { } else {
val target = targetDir / dir.name val target = targetDir / dir.name
IO.createDirectories(Seq(target.getParentFile)) IO.createDirectories(Seq(target.getParentFile))
IO.copy(Seq(dir -> target)) copyWithGZ(dir, target)
Seq(target)
} }
} }
} }
@ -611,7 +622,9 @@ def compileElm(
) )
val out = proc.!! val out = proc.!!
logger.info(out) logger.info(out)
Seq(target) val targetGZ = file(target.toString + ".gz")
IO.gzip(target, targetGZ)
Seq(target, targetGZ)
} }
def createWebjarSource(wj: Seq[ModuleID], out: File): Seq[File] = { def createWebjarSource(wj: Seq[ModuleID], out: File): Seq[File] = {

View File

@ -1,27 +1,17 @@
package docspell.restserver.webapp package docspell.restserver.webapp
import cats.data.Kleisli
import cats.data.OptionT
import cats.effect._ import cats.effect._
import org.http4s.HttpRoutes import org.http4s.HttpRoutes
import org.http4s.server.staticcontent.NoopCacheStrategy import org.http4s.Method
import org.http4s.server.staticcontent.WebjarService.{Config => WebjarConfig, WebjarAsset} import org.http4s.Response
import org.http4s.server.staticcontent.webjarService import org.http4s.StaticFile
object WebjarRoutes { object WebjarRoutes {
def appRoutes[F[_]: Effect]( private[this] val suffixes = List(
blocker: Blocker
)(implicit C: ContextShift[F]): HttpRoutes[F] =
webjarService(
WebjarConfig(
filter = assetFilter,
blocker = blocker,
cacheStrategy = NoopCacheStrategy[F]
)
)
def assetFilter(asset: WebjarAsset): Boolean =
List(
".js", ".js",
".css", ".css",
".html", ".html",
@ -36,6 +26,25 @@ object WebjarRoutes {
".ttf", ".ttf",
".yml", ".yml",
".xml" ".xml"
).exists(e => asset.asset.endsWith(e)) )
def appRoutes[F[_]: Effect](
blocker: Blocker
)(implicit CS: ContextShift[F]): HttpRoutes[F] =
Kleisli {
case req if req.method == Method.GET =>
val p = req.pathInfo
if (p.contains("..") || !suffixes.exists(p.endsWith(_)))
OptionT.pure(Response.notFound[F])
else
StaticFile.fromResource(
s"/META-INF/resources/webjars$p",
blocker,
Some(req),
true
)
case _ =>
OptionT.none
}
} }