feat(14): enabling public resource serving

this time with "staticResources" for files in 'main/resources' which
should be copied and put onto classpath by the scala compilation, yay
This commit is contained in:
efim 2023-06-30 16:40:40 +00:00
parent ec5cac0680
commit 83c75ad3a9
3 changed files with 39 additions and 36 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -1,15 +1,21 @@
<!doctype html> <!DOCTYPE html>
<html class="no-js" lang=""> <html class="no-js" lang="">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge"> <meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>Initial flie</title> <title>Initial flie</title>
<meta name="description" content=""> <meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="icon"
type="image/png"
sizes="32x32"
href="../public/images/favicon-32x32.png"
th:href="'public/images/favicon-32x32.png'"
/>
<link rel="apple-touch-icon" href="/apple-touch-icon.png"> <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<!-- Place favicon.ico in the root directory --> <!-- Place favicon.ico in the root directory -->
</head> </head>
<body> <body>
<!--[if lt IE 8]> <!--[if lt IE 8]>
@ -21,10 +27,7 @@
<![endif]--> <![endif]-->
<main> <main>
<h1>Hello!</h1> <h1>Hello!</h1>
<p th:text="${myVar}" > <p th:text="${myVar}">with static text</p>
with static text
</p>
</main> </main>
</body> </body>
</html> </html>

View File

@ -26,8 +26,7 @@ object Main {
server.main(Array.empty) server.main(Array.empty)
} }
def main(args: Array[String]): Unit = def main(args: Array[String]): Unit = {
{
println(s"got args : $args") println(s"got args : $args")
ParserForMethods(this).runOrExit(args) ParserForMethods(this).runOrExit(args)
} }
@ -43,11 +42,12 @@ object Main {
templateEngine.setTemplateResolver(templateResolver) templateEngine.setTemplateResolver(templateResolver)
@cask.get("/") @cask.get("/")
def index() = { def index(req: cask.Request) = {
val context = new Context() val context = new Context()
println(s"getting request for ${req.remainingPathSegments}")
context.setVariable( context.setVariable(
"myVar", "myVar",
"Hello, from Scala world" "Hello, from Scala world!"
) )
val result = templateEngine.process("index", context) val result = templateEngine.process("index", context)
cask.Response( cask.Response(
@ -56,11 +56,11 @@ object Main {
) )
} }
@cask.staticFiles("/dist") @cask.staticResources("/public")
def distFiles() = "dist" def publicFiles(req: cask.Request) = {
@cask.staticFiles("/public") println(s"getting request for ${req.remainingPathSegments}")
def publicFiles() = "public" "public"
}
initialize() initialize()
} }