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,30 +1,33 @@
<!doctype html>
<!DOCTYPE html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Initial flie</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>Initial flie</title>
<meta name="description" content="" />
<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">
<!-- Place favicon.ico in the root directory -->
</head>
<body>
<!--[if lt IE 8]>
<p class="browserupgrade">
You are using an <strong>outdated</strong> browser. Please
<a href="http://browsehappy.com/">upgrade your browser</a> to improve
your experience.
</p>
<![endif]-->
<main>
<h1>Hello!</h1>
<p th:text="${myVar}" >
with static text
</p>
</main>
</body>
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<!-- Place favicon.ico in the root directory -->
</head>
<body>
<!--[if lt IE 8]>
<p class="browserupgrade">
You are using an <strong>outdated</strong> browser. Please
<a href="http://browsehappy.com/">upgrade your browser</a> to improve
your experience.
</p>
<![endif]-->
<main>
<h1>Hello!</h1>
<p th:text="${myVar}">with static text</p>
</main>
</body>
</html>

View File

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