Prettynice

Use this module to define and start a Prettynice web server.

type alias Program model msg = Program (Model model) (Msg model msg)

The definition of your Prettynice program.

Defining your program

defineProgram :
{ init : Environment -> Init model msg
, router : model -> Request -> Response msg -> Task Never (Response msg)
}
-> Program model msg

Define a Prettynice web server.

Servers are defined with two functions: init is used to start your program and router will be called on every request and should return a task that resolves to a response.

See server/src/Main.gren in the example projects for how to use this in practice.

Starting your pgoram

type alias Init model msg = Task { model : Model model, command : Cmd (Msg model msg) }

Init task for starting your Prettynice program. Created with startProgram.

startProgram :
{ env : Environment
, host : String
, port_ : Int
, model : model
}
-> Init model msg

Start a Prettynice web server. You should call this in your init function.

It can be wrapped in one or more calls to Init.await if you need to run a task or initialize any subsystems before starting. See the database example for an example of this.

If you are using defineFullProgram and want to include a command as part of your init, you can use startFullProgram instead.

See server/src/Main.gren in the example projects for how to use this in practice.

Messages, Commands, and Subscriptions

Sometimes init and router are not enough. Maybe you need access to commands or ports on the server side. If so, you can use these functions to create a program that includes update and subscriptions.

defineFullProgram :
{ init : Environment -> Init model msg
, update : msg -> model -> { model : model, command : Cmd msg }
, subscriptions : model -> Sub msg
, router : model -> Request -> Response msg -> Task Never (Response msg)
}
-> Program model msg

Define a Prettynice web server that uses the full Elm Architecture.

This is the same as defineProgram, but with the addition of update and subscription functions. They work just like they do in a normal Gren node program.

You should only need this if your server needs access to commands (e.g. for server-side ports) or subscriptions. If you don't need them, you probably want defineProgram.

See server/src/Main.gren in the server-side-tea example for how defineFullProgram is used in practice.

startFullProgram :
{ env : Environment
, host : String
, port_ : Int
, model : model
, command : Cmd msg
}
-> Init model msg

Start a Prettynice web server that includes an init command.

This works just like startProgram with the addition of a command field to send a command on init.

See server/src/Main.gren in the bytes example for an example usage of startFullProgram (it reads a file on init).