feat(13): starting simple web server

This commit is contained in:
efim 2023-06-28 15:35:34 +00:00
parent 28f2cf281a
commit d35bf9735c
1 changed files with 20 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package testimonialsgrid package testimonialsgrid
import mainargs.{main, arg, ParserForMethods} import mainargs.{main, arg, ParserForMethods}
import cask.main.Routes
object Main { object Main {
@main def run( @main def run(
@ -9,10 +10,28 @@ object Main {
@arg(name = "host", doc = "Host on which server will start serving.") @arg(name = "host", doc = "Host on which server will start serving.")
hostArg: String = "localhost" hostArg: String = "localhost"
): Unit = { ): Unit = {
val a = 1
println(s"Will start server on ${hostArg}:${portArg}") println(s"Will start server on ${hostArg}:${portArg}")
val server = new cask.Main {
override def allRoutes: Seq[Routes] = Seq(AppRoutes())
override def port: Int = portArg
override def host: String = hostArg
}
server.main(Array.empty)
} }
def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args) def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args)
case class AppRoutes()(implicit cc: castor.Context, log: cask.Logger) extends cask.Routes {
@cask.get("/")
def index() = {
cask.Response("Hello")
}
@cask.staticFiles("/dist")
def distFiles() = "dist"
@cask.staticFiles("/public")
def publicFiles() = "public"
initialize()
}
} }