-
Notifications
You must be signed in to change notification settings - Fork 1
/
HelloFile.elm
45 lines (37 loc) · 1.24 KB
/
HelloFile.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module HelloFile exposing (main)
import Error
import File
import Json.Decode
import Response
import Result.Extra
import Server exposing (Config, Flags, Request, Response)
import Status exposing (Status(..))
main : Server.Program
main =
Server.program
{ init = init
, handler = handler
}
init : Flags -> Config
init _ =
Server.baseConfig
handler : Request -> Response
handler request =
case Server.getPath request of
[] ->
File.load "./examples/hello.html"
|> Server.onSuccess
(Json.Decode.decodeValue Json.Decode.string
>> Result.map
(\file ->
Response.ok
|> Response.setBody file
|> Server.respond request
)
>> Result.mapError
(Json.Decode.errorToString >> Response.error >> Server.respond request)
>> Result.Extra.merge
)
|> Server.onError (Error.toString >> Response.error >> Server.respond request)
_ ->
Server.respond request Response.notFound