Closed imclerran closed 9 months ago
Thanks for reporting this @imclerran! I have not had the time to set up proper testing for basic-webserver yet, hence this easily detectable bug. I'll do some debugging.
I could not reproduce this with the same nightly and this source code:
app "helloweb"
packages { pf: "https://github.com/roc-lang/basic-webserver/releases/download/0.2.0/J6CiEdkMp41qNdq-9L3HGoF2cFkafFlArvfU1RtR4rY.tar.br" }
imports [
pf.Stdout,
pf.Task.{ Task },
pf.Http.{ Request, Response },
pf.Utc,
]
provides [main] to pf
main : Request -> Task Response []
main = \req ->
# Log request date, method and url
date <- Utc.now |> Task.map Utc.toIso8601Str |> Task.await
{} <- Stdout.line "\(date) \(Http.methodToStr req.method) \(req.url)" |> Task.await
Task.ok { status: 200, headers: [], body: Str.toUtf8 "<b>Hello, world!</b>\n" }
❯ ./roc examples/helloweb.roc
Listening on localhost port 8000
2024-01-01T12:59.51Z GET /
2024-01-01T12:59.51Z GET /favicon.ico
Can you share your exact code and roc command @imclerran?
Yes, here is my code:
app "helloweb"
packages { pf: "https://github.com/roc-lang/basic-webserver/releases/download/0.2.0/J6CiEdkMp41qNdq-9L3HGoF2cFkafFlArvfU1RtR4rY.tar.br" }
imports [
pf.Stdout,
pf.Task.{ Task },
pf.Http.{ Request, Response },
pf.Utc,
]
provides [main] to pf
main : Request -> Task Response []
main = \req ->
# Log request date, method and url
date <- Utc.now |> Task.map Utc.toIso8601Str |> Task.await
{} <- Stdout.line "\(date) \(Http.methodToStr req.method) \(req.url)" |> Task.await
Task.ok { status: 200, headers: [], body: Str.toUtf8 "<b>Hello, world!</b>\n" }
Note that this is identical to the code in the readme, except that the package has been updated to the 0.2.0
release of the platform. Also note that I get the same error when using the 0.1
release.
I also get the same error when running the command.roc example, although since I don't have the repo locally, I am again using the url to download the platform files (both 0.2.0 and 0.1), but otherwise leaving the code unchanged.
My roc command was roc dev helloweb.roc
. However when trying again today, I can't reproduce the error either.
Not sure what happened as I tried multiple times yesterday with multiple versions of server code, and multiple platform versions. Every run resulted in a crash on the first HTTP request.
Given the fact that I can't reproduce, I think it's safe to close this issue.
When running the "helloweb" example webserver from the readme.md file (updated to use the 0.2.0 release), the webserver runs successfully, but as soon as a request is made to the server by loading 127.0.0.1:8000 in a browser, the application crashes with the following message (note that no backtrace is printed):
Note that I am using Roc version:
roc_nightly-macos_apple_silicon-2023-12-29-4569770c82c