|
|
@ -9,7 +9,7 @@ import zio.stream.ZStream
|
|
|
|
import java.nio.file.{Files, Path}
|
|
|
|
import java.nio.file.{Files, Path}
|
|
|
|
import scala.collection.mutable
|
|
|
|
import scala.collection.mutable
|
|
|
|
|
|
|
|
|
|
|
|
class ResourceDispatcher(pagesLocation: Path) {
|
|
|
|
class WebService(pagesLocation: Path) {
|
|
|
|
|
|
|
|
|
|
|
|
private val resources = resolveResources
|
|
|
|
private val resources = resolveResources
|
|
|
|
|
|
|
|
|
|
|
@ -25,6 +25,7 @@ class ResourceDispatcher(pagesLocation: Path) {
|
|
|
|
ZIO.attempt(Response.status(status))
|
|
|
|
ZIO.attempt(Response.status(status))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private def resolveResources: Map[String, Body] = {
|
|
|
|
private def resolveResources: Map[String, Body] = {
|
|
|
|
|
|
|
|
|
|
|
|
val map = mutable.HashMap.empty[String, Body]
|
|
|
|
val map = mutable.HashMap.empty[String, Body]
|
|
|
@ -32,17 +33,23 @@ class ResourceDispatcher(pagesLocation: Path) {
|
|
|
|
def resolveAll(loc: Path): Unit = {
|
|
|
|
def resolveAll(loc: Path): Unit = {
|
|
|
|
Files.list(loc)
|
|
|
|
Files.list(loc)
|
|
|
|
.forEach {
|
|
|
|
.forEach {
|
|
|
|
case d if Files.isDirectory(d) => resolveAll(d)
|
|
|
|
case d if Files.isDirectory(d) => resolveAll(d)
|
|
|
|
case f =>
|
|
|
|
case f =>
|
|
|
|
val body = Body.fromFile(f.toFile)
|
|
|
|
val body = Body.fromFile(f.toFile)
|
|
|
|
val fileName = f.toString
|
|
|
|
val fullPath = f.toString
|
|
|
|
map.put(fileName, body)
|
|
|
|
val fileName = f.getFileName.toString
|
|
|
|
val extension = fileName.drop(fileName.indexOf('.'))
|
|
|
|
val purename = fileName.take(fileName.indexOf('.'))
|
|
|
|
|
|
|
|
|
|
|
|
val dirPath = f.getParent.toString
|
|
|
|
map.put(fullPath, body)
|
|
|
|
if (extension == ".html")
|
|
|
|
|
|
|
|
map.put(dirPath, body) //also bind the dir path with the index body
|
|
|
|
//also bind the dir path with the index body
|
|
|
|
else map.put(dirPath + extension, body)
|
|
|
|
if (purename == "index" || purename == f.getParent.getFileName.toString) {
|
|
|
|
|
|
|
|
val extension = fullPath.drop(fullPath.indexOf('.'))
|
|
|
|
|
|
|
|
val dirPath = f.getParent.toString
|
|
|
|
|
|
|
|
if (extension == ".html")
|
|
|
|
|
|
|
|
map.put(dirPath, body)
|
|
|
|
|
|
|
|
else map.put(dirPath + extension, body)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|