feat: accepting port and host
using lihaoyi mainargs, yay and running .main on custom cask.Main had a problem with run arguments "port" and "host" having same name as inner attributes of cask.Main and i guess infinite recursion when i tried to reference outer args, the more you know
This commit is contained in:
parent
a5402c1fe2
commit
dbe2cd47da
|
@ -1,15 +1,34 @@
|
|||
//> using dep com.lihaoyi::cask:0.9.1
|
||||
//> using dep com.lihaoyi::scalatags:0.12.0
|
||||
|
||||
//> using dep com.lihaoyi::mainargs:0.5.0
|
||||
package pricegrid
|
||||
|
||||
import scalatags.Text.all._
|
||||
import scalatags.Text.tags2
|
||||
import scalatags.Text.short
|
||||
import mainargs.{main, arg, ParserForMethods}
|
||||
|
||||
case class AppRoutes(someVal: String)(implicit cc: castor.Context,
|
||||
object App {
|
||||
@main
|
||||
def run(@arg(name = "post", short = 'p', doc = "Port on which server will start serving.")
|
||||
portArg: Int = 8080,
|
||||
@arg(name = "host", doc = "Host on which server will start serving.")
|
||||
hostArg: String = "localhost") = {
|
||||
println(s"Will start server on ${hostArg}:${portArg}")
|
||||
|
||||
val server = new cask.Main {
|
||||
override val allRoutes = Seq(AppRoutes())
|
||||
override def port = portArg
|
||||
override def host = hostArg
|
||||
}
|
||||
server.main(Array.empty)
|
||||
}
|
||||
|
||||
def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args)
|
||||
}
|
||||
|
||||
case class AppRoutes()(implicit cc: castor.Context,
|
||||
log: cask.Logger) extends cask.Routes {
|
||||
println(s"> Starting server with param $someVal")
|
||||
|
||||
@cask.get("/")
|
||||
def index() = Page.wholePageMarkup
|
||||
|
||||
|
@ -21,10 +40,3 @@ case class AppRoutes(someVal: String)(implicit cc: castor.Context,
|
|||
|
||||
initialize()
|
||||
}
|
||||
object App extends cask.Main {
|
||||
override val allRoutes = Seq(AppRoutes("hello!"))
|
||||
override def main(args: Array[String]) = {
|
||||
println(s"server starting with args: $args")
|
||||
super.main(Array.empty)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue