Как использовать Elm реактор для доступа к файлам через HTTP-запрос?
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 ответ
Решение
Ваш комментарий имеет разные расширения файлов. Вы сказали, что создали src/test.txt
но вы получаете 404, потому что вы просите .text
расширение.
Попробуйте перейти на http://localhost:8000/src/test.txt