I’m following the same course. At one point when they’re reading the about.html file, they typed the path as “../../page/about.html”, because the handler.ex file lives 2 levels down than the root.
Here is the screenshot.
When I did the same, it gave me :enoent (file not found), but when I typed the path as “pages/about.html”, it worked.
Is there anything changed in BEAM that it now handles files paths differently? (or what they did differently?)
Here is the function:
def route(%{method: "GET", path: "/about"} = conv) do
case File.read("pages/about.html") do
{:ok, content} ->
%{conv | status: 200, resp_body: content}
{:error, :enoent} ->
%{conv | status: 404, resp_body: "File not found!"}
{:error, reason} ->
%{conv | status: 500, resp_body: "File error: #{reason}"}
end
end
And here is the files and folders structure:
.
├── config
│ └── config.exs
├── lib
│ ├── servy
│ │ └── handler.ex
│ └── servy.ex
├── mix.exs
├── pages
│ └── about.html
├── README.md
└── test
├── servy_test.exs
└── test_helper.exs























