Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    k0ala
    @k0ala
    @lihaoyi thank you! I guess it doesn't help that I am an http and web noob (in addition to being a cask noob), I only know scala and decided it was time to learn how to make a website :) Btw, do you plan to refresh the "hands-on-scalajs" website sometime? It is very nicely written but outdated
    Li Haoyi
    @lihaoyi
    (the test suite has a lot of good stuff in general; basically every route in every example has a test case that calls it, and AFAIK all of them should pass)
    haha yeah I can tell, localhost vs 0.0.0.0 is something I'd expect non-scala-web-developers to know :)
    I don't have any concrete plans for updating hands-on-scala-js; I'm still a bit burnt out writing hands-on-scala-programming in 2019-2020 era, so not sure I'd be able to pick up a big project like that
    I wrote hands-on-scala-js when my curiosity was stronger, my standards were lower, and my non-work responsibilities were much fewer haha
    k0ala
    @k0ala
    yeah that's understandable, it blows my mind how many things you've produced
    Li Haoyi
    @lihaoyi
    it could definitely do with a refresh, e.g. using Mill instead of SBT, using Cask instead of Akka-HTTP, using DefinitelyScala facades, using some other OSS projects like Slinky,
    k0ala
    @k0ala
    that sounds awesome ;)
    Li Haoyi
    @lihaoyi
    nope
    k0ala
    @k0ala
    In the meantime I figured out how to upload an image :) I ended up using the raw cask.Request as you suggested. Now I am struggling with the notion of "being logged in", i.e. only allowing users access if they have successfully entered their password. If you have any tutorial/example on this, I am all ears!
    (I went through some AWS Cognito tutorial, so I could use that for the login part. What remains unclear to me is how to use the token or code that is returned by Cognito.)
    k0ala
    @k0ala
    I got a bit of education on JWT tokens, here is how I think it might work with Cognito: 1) user gets sent to Cognito login, receives a token. 2) scalaJS saves the token and adds it to every request header going forward. 3) cask validates the token at every request. Does that sound reasonable? Or am I heading in the wrong direction?
    k0ala
    @k0ala
    I guess I should ask this question in the scala-js/scala-js gitter instead
    lakinwecker
    @lakinwecker
    Good morning, hope everyone is doing well. I'm somewhat new to Scala development, but am tinkering around in using it for web stuff (coming from the python/django world). I'm using scalatags, and am replacing a very simple very ancient php site which has very little server side processing. I like the simplicity of Cask, but am running into issues doing simple form processing using it. For example, if I make a handler which expects a radio button value, but the user submits without the radio button, the resulting page is a 400, rather than something I can handle to display the appropriate error message. I realize that most people do this sort of form submission in JS these days, but I'd like to know how to handle these sorts of things within cask. Does anyone have a recommended method for taking a POST with a urlencoded body and doing some very basic validation (required fields, etc) and turning it into a case class instance or a list of error messages?
    I tried googling for some libraries, and didn't find much, and I've read the cask documentation and couldn't figure it out. Where I ended up was: https://gist.github.com/lakinwecker/b53b59f09c6653e93b14f9e4364c28a2 but if the cabins value is missing from the POST, then cask returns a 400 instead of calling this method with a None for the cabins option.
    Li Haoyi
    @lihaoyi
    @lakinwecker could you try adding a default value = None to your optional parameter see if that can make it happy
    Simon Miles
    @drsimonmiles

    Hello. I've been trying out Cask and got an HTTP server with a Scala.js front-end working without problems, and all seems great. I then wanted to try out Websockets but have got stuck. I tried copying verbatim the first example from the codebase as a starting point:
    https://github.com/com-lihaoyi/cask/blob/master/example/websockets/app/src/Websockets.scala
    but I get compilation errors.

    case cask.Ws.Text("") => channel.send(cask.Ws.Close())
    no implicit argument of type sourcecode.FileName was found for parameter fileName of method send in class BaseActor

    From looking at the code, I understand that WsActor inherits from Castor's BaseActor (via SimpleActor) and the latter's send method requires an implicit sourcecode fileName and line. I don't understand what these could be in the context of Websockets (but I'm quite new to Websockets).
    I tried running the websockets example test from the Cask codebase, in case it was something odd in my own setup, but hit another problem doing that. I think it's a separate Mill-related question so I'll omit details.
    Any suggestion how I might be getting the compilation error above?

    Li Haoyi
    @lihaoyi
    are you on Scala 3?
    feels like there's some dependency scala version conflicts
    Simon Miles
    @drsimonmiles
    Ah yes, sorry I should have said that, I am using Scala 3
    Simon Miles
    @drsimonmiles
    I've added dependency on com.lihaoyi::castor:0.2.0 and it appears to compile fine now. Thanks again.
    k0ala
    @k0ala
    I suppose the documentation about getRawParams is no longer valid? https://com-lihaoyi.github.io/cask/#extending-endpoints-with-decorators
    k0ala
    @k0ala
    Can I make cask log with logback?
    lakinwecker
    @lakinwecker

    @lakinwecker could you try adding a default value = None to your optional parameter see if that can make it happy

    This is so obvious in hindsight, why didn't I try this?

    k0ala
    @k0ala
    How should I specify the implicit params FileName and Line for castor actors?
    no implicit argument of type sourcecode.FileName was found for parameter fileName of method send in class BaseActor
    Simon Miles
    @drsimonmiles

    How should I specify the implicit params FileName and Line for castor actors?
    no implicit argument of type sourcecode.FileName was found for parameter fileName of method send in class BaseActor

    @k0ala That was the problem I raised above, I think. I fixed it (at least for compilation) by adding a dependency on a newer version of castor than the one used by cask, com.lihaoyi::castor:0.2.0

    k0ala
    @k0ala
    @drsimonmiles ah yes, thanks!
    k0ala
    @k0ala
    Does somebody have an example on how to configure cask to log with logback?
    Jared Neil
    @JaredNeil
    Is there an example or existing decorator like postJson, but that uses uPickle to parse to a case class? I'm thinking something like how you can set up MainArgs to parse to custom types.
    In use @jsonApi(TodoRoutes.getATodo) def aTodo(id: Int): Option[Todos] = { myDB.aTodo(id).headOption } which is a cask route... the decorator wraps the result into a response.
    Christian Ternus
    @ternus
    Hi! I'm trying to get the examples to work, but I'm running into this error:
    [$]> mill -w app.runBackground
    Compiling /Users/ternus/src/cask-0.7.12/example/minimalApplication/build.sc
    Cannot resolve app. Did you mean all?
    If I do mill resolve _, it shows:
    [$]> mill resolve _
    [1/1] resolve
    all
    clean
    inspect
    par
    path
    plan
    resolve
    show
    shutdown
    version
    visualize
    visualizePlan
    Pathikrit Bhowmick
    @pathikrit
    Is there a way to run cask server in watch mode using sbt? Something like sbt> ~server/runMain Server ? This will hot reload the server on code changes?
    2 replies
    kurgansoft
    @kurgansoft
    Is it possible to use Cask with livejs?
    The problem is that livejs emits head requests to check if a file has changed, but cask returns with a 405 error.
    Is there a simple way to enable head requests for static files(cask.staticFiles annotation)?
    jetaggart
    @jetaggart
    Hello, is there a way to install middleware with cask? I'm not seeing how I do something like CORS/logging easily. Sorry if I'm missing something obvious, cask looks perfect if I can just figure this out!
    Li Haoyi
    @lihaoyi
    you can use custom decorators for that
    jetaggart
    @jetaggart
    do you have an example by chance?
    I'm confused on how a decorator for a POST method, that receives a pre-flight check from the browser with a OPTIONS method can be handled by a decorator
    Li Haoyi
    @lihaoyi
    I don't think the decorators can have state spanning multiple requests
    you'll have to implement that out of band in your own code
    jetaggart
    @jetaggart
    gotcha, thank you!
    Objektwerks
    @objektwerks
    A Cask/Undertow server doesn't block in main. Why not?
    Is there a more elegant solution? What am I missing? Thanks in advance! :)
    Objektwerks
    @objektwerks
    Also, what is the suggested method of testing a Cask server. I have a few ideas , but would like to hear from the gurus. Thanks in advance!
    Li Haoyi
    @lihaoyi
    the cask examples/ folder projects have unit tests
    you can use that as a starting point and evolve the tests from there
    Objektwerks
    @objektwerks
    @lihaoyi Ok, I'll examine those examples more closely. Thanks!
    urbanchr
    @urbanchr

    I am trying to adapt the chatbot example from Hands-on-Scala to use some buttons and to modify a counter. At the moment I have

    @cask.get("/")
      def hello() = 
          doctype("html")(
          html(
            head(href := bootstrap, script(src := "/static/app2.js")), 
            body( 
                div(id := "messageList")(i(color.red)(cnt)),
                form(onsubmit := "submitForm(); return false")(
                    button(`type` := "submit", id := "nameInput",  value :="1")("1")
                    //button(`type` := "submit", id := "nameInput",  value :="2")("2")
                )
            )
          ))
    
      @cask.postJson("/")
      def postChatMsg(name: String) = {
        cnt = cnt + 1
        ujson.Obj("success" -> true, "txt" -> frag(i(color.red)(cnt)).render, "err" -> "oops")
      }

    However, when I uncomment the second button, I receive a 400 (Bad Request). The helper app2.js is as follows:

    function submitForm() {
      fetch(
        "/",
        {method: "POST", body: JSON.stringify({name: nameInput.value})}
      ).then(response => response.json())
       .then(json => {
          if (json["success"]) {
            messageList.innerHTML = json["txt"]
          }
      })
    }

    What is the right approach to get more than one button to work? Thanks a lot!