I am using a Javascript library named qooxdoo for the frontend. The issue I have with this library is that when it is used like SDK, it makes extra requests for file in folders different than the main folder. This is not an issue when the final app is made in a build version. Anyway here is an example.
The main script is loaded from http://localhost:4000/js/qssite/source/script/qssite.js
and it starts requiring supplementary scripts from http://localhost:4000/script/qssite.a1b55c5841e0.js
and resources like icons from http://localhost:4000/qooxdoo/framework/source/resource/qx/decoration/Modern/window-captionbar-buttons-combined.png
which are saluted with a big red 404
.
After some trial and error I came to this solution. In the file endpoint.ex, under the plug Plug.Static ...
call I added these lines
# for debugging the javascript application
if :dev == Mix.env() do
plug Plug.Static,
at: "/",
from: {:qssite, "priv/static/js/qssite/source/"},
only_matching: ~w(script)
plug Plug.Static,
at: "/qooxdoo/framework/source",
from: Path.relative_to_cwd("../qooxdoo/framework/source"),
only: ~w(resource)
end
And now it works.
Given that this piece of code is needed only while I develop the application and should be excluded in production
- Is my call to
:dev == Mix.env()
appropriate or should I check some other condition? - Is there any better alternative than adding it to endpoint.ex? I know I could do something with router.ex but it doesn’t seem that clean to me. Can I do it even cleaner than what I already have?