1

I have defined a plug in my App.Endpoint module in the following way:

plug(
  Plug.Static,
  at: "/",
  from: :main_web,
  gzip: false,
  only: ~w(css fonts images webfonts favicon.ico robots.txt sw.js manifest.json js/app.js),
  headers: %{"Access-Control-Allow-Origin" => "*"}
)

Everything works as expected except that this plug is not applied for /js/app.js

I am currently not able to serve just /js/app.js, but instead am only able to specify js which will serve all the files in the /js directory.

How can I specify just this js/app.js file and not others?

I have tried

only: ~w(... app.js)
only_matching: ~w(... js/app.js)

But I always receive 404 for /js/app.js

Sam Houston
  • 3,413
  • 2
  • 30
  • 46
  • From the [source](https://github.com/elixir-plug/plug/blob/10948b83a4441d4ef0f09a7563d307b1d3903080/lib/plug/static.ex) it looks like only the first segment of the URL is checked against the `only` list. You could add a special route for `/js/app.js` and manually serve the JS file using `send_file`. – Dogbert May 25 '18 at 12:17

0 Answers0