0

elm 0.19

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

then create src/test.elm and src/test.txt:

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


$ elm reactor

then navigate to:

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

so the browser window shows:

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.

but the browser console shows:

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

Why can't elm reactor locate 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
        }

Solved

In test.elm, the url "test.txt" was falsely spelled to "test.text".

glennsl
  • 28,186
  • 12
  • 57
  • 75
sof
  • 9,113
  • 16
  • 57
  • 83

1 Answers1

2

Your comment has different file extensions. You said you created src/test.txt but you are getting a 404 because you are asking for a .text extension.

Try going to http://localhost:8000/src/test.txt

Chad Gilbert
  • 36,115
  • 4
  • 89
  • 97
  • I need access `test.txt`via http from `test.elm` program when it is running under `elm reactor`. – sof Oct 09 '18 at 18:20
  • 2
    It works correctly for me when the file name in `test.elm` matches the text file name on disk. Are you certain yours match in real life as well? – Chad Gilbert Oct 09 '18 at 18:24