#How do I start a wisp server?

1 messages · Page 1 of 1 (latest)

sick surge
#

Is there a trick to get the wisp server running? When I run gleam run in the examples folder it says running app.main but when I go to port 8000 nothing is running, and the terminal is available immediately after. My io.print statements are also not printing so I suspect there's something else to do.

examples/0-hello-world(main) $ gleam run
   Compiled in 0.01s
    Running app.main

gleam --version
gleam 0.32.4
spice yacht
#

You’re likely missing a process.sleep_forever, see the hello world example:


import gleam/erlang/process
import mist
import wisp
import app/router

pub fn main() {
  // This sets the logger to print INFO level logs, and other sensible defaults
  // for a web application.
  wisp.configure_logger()

  // Here we generate a secret key, but in a real application you would want to
  // load this from somewhere so that it is not regenerated on every restart.
  let secret_key_base = wisp.random_string(64)

  // Start the Mist web server.
  let assert Ok(_) =
    wisp.mist_handler(router.handle_request, secret_key_base)
    |> mist.new
    |> mist.port(8000)
    |> mist.start_http

  // The web server runs in new Erlang process, so put this one to sleep while
  // it works concurrently.
  process.sleep_forever()
}
#

Oh wait are you running the example directly from the repo? It should work 🤔

amber sonnet