如何使用Elm Reactor通过http请求访问文件?

时间:2018-10-09 18:09:34

标签: elm elm-reactor

elm 0.19

$ mkdir myprj; cd myprj; elm init; elm install elm/http

然后创建src / test.elm和src / test.txt:

$ tree
.
├── elm.json
└── src
    ├── test.elm
    └── test.txt


$ elm reactor

然后导航至:

http://localhost:8000/src/test.elm

因此浏览器窗口显示:

This is a headless program, meaning there is nothing to show here.

I started the program anyway though, and you can access it as `app` in the developer console.

但浏览器控制台显示:

Failed to load resource: the server responded with a status of 404 (Not Found) test.text:1

为什么elm reactor找不到test.txt

test.txt:

hi

test.elm:

import Http


init () =
    ( "", Http.send Resp <| Http.getString "test.text" )


type Msg
    = Resp (Result Http.Error String)


update msg model =
    case msg of
        Resp result ->
            case result of
                Ok body ->
                    ( Debug.log "ok" body, Cmd.none )

                Err _ ->
                    ( "err", Cmd.none )


subscriptions model =
    Sub.none


main =
    Platform.worker 
        { init = init
        , update = update
        , subscriptions = subscriptions
        }

已解决

在test.elm中,URL“ test。 txt ”被错误地拼写为“ test。 text ”。

1 个答案:

答案 0 :(得分:2)

您的评论具有不同的文件扩展名。您说您创建了src/test.txt,但由于要求扩展.text而得到404。

尝试转到http://localhost:8000/src/test.txt