From 83c75ad3a94e2a1745c2b4cc253d6dc4be41dac6 Mon Sep 17 00:00:00 2001 From: efim Date: Fri, 30 Jun 2023 16:40:40 +0000 Subject: [PATCH] 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 --- .../resources/public/images/favicon-32x32.png | Bin 0 -> 1063 bytes .../src/main/resources/templates/index.html | 57 +++++++++--------- .../main/scala/rockpaperscissors/Main.scala | 18 +++--- 3 files changed, 39 insertions(+), 36 deletions(-) create mode 100644 14-rock-paper-scissors/src/main/resources/public/images/favicon-32x32.png diff --git a/14-rock-paper-scissors/src/main/resources/public/images/favicon-32x32.png b/14-rock-paper-scissors/src/main/resources/public/images/favicon-32x32.png new file mode 100644 index 0000000000000000000000000000000000000000..1e2df7f089f46dd930239e418bf13e8e4c1cca0f GIT binary patch literal 1063 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dyEa{HEjtmSN`?>!lvVtU&J%W50 z7^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+081EY0-Plzi}!G9Wnr(eF` z|M+F+!xzhMK3;zF(cgdn_B?v|`rD7+fB)V2@MY=EN9|{BEWPpQ{f}RtfBl|!^+Ea3 z%d2iZe)i@2x9`6{eg66V&!4ULpSPU4KJ)Uu^RM22`~BzO$wz&&PyPA(@7<4I`yRjQ zJAZr1#XB#){D-o5+r^Vjdc3)fsquh@R{^yA;Z|8C!Zw`1zDvzMNK{QUFr z^G~yvU&yK5nOnE3q5ts2d8Z#d`S9=G|MwriU%2{m%ii0owp@Sy>dXGuA$NemCsPvS z7YvLEt(>(tKmBDkpML+hROc(RL;oBPGFiO5x8~1ErS?rgb&N^g?k~Ih+L^ zk;M!Q+`=Ht$S`Y;1W=H@#M9T6{SlWiKeL>x)y)*39#2mf#}JFtt&`J}n+ycniko-@ z3;26vOWyCzeS7I$?C$UX{_kIKV}WAF+24(KRQ;Wbm=(hXgpO=b(eBb|byZ~P5M3dt zyDB-nDx`Zw9LoWN-GrY`kHxRfy}Q3KfBxRdclJCv_%N_mL-x0j+x*I+s%JIY&vgg3Y zTes?8j%DMbh5PocynFBNZJq}$w`Q+tKfe6=^y}tkkv_Zb+uQBmSHB|O-+X(*4%OrO zQF%8%OSj*z`t$7X`oHyz%ReTa40^8r7Z}c}C9V-ADTyViR>?)FK#IZ0z|cb1&_LJF zGQ`l-%D~vl*g)IB$jZQAv*1E06b-rgDVb@NxHTN|kz5AU01WSllAy$Lg@U5|w9K4T zg_6pGRE5lfl4J&kiaC!z@o*G|X=t4CKYhmYX%GXmGPhnbx3IFX_hb=fVFi~4lfx;@ u%9}$JPT#n4;>ejJGDp}?H+U@Y(qnifE?Dx($#g2v3I + - - - - Initial flie - - + + + + Initial flie + + + - - - - - - -
-

Hello!

-

- with static text -

-
- - + + + + + +
+

Hello!

+

with static text

+
+ diff --git a/14-rock-paper-scissors/src/main/scala/rockpaperscissors/Main.scala b/14-rock-paper-scissors/src/main/scala/rockpaperscissors/Main.scala index 6538b3a..9174501 100644 --- a/14-rock-paper-scissors/src/main/scala/rockpaperscissors/Main.scala +++ b/14-rock-paper-scissors/src/main/scala/rockpaperscissors/Main.scala @@ -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() }