hudson2010

hudson2010

Challenge with Serving Static files

Hello guys ,
I have set up some project , but I have som e bit of challenge with serving static files with the plug module

23:03:44.817 [debug] GET /home
 
23:03:44.817 [debug] Sent 200 in 32µs
 
23:03:44.849 [debug] GET /priv/js/test.js
 
*23:03:44.849 [debug] Sent 404 in 24µs*
==============================
Routes :
plug(Plug.Logger, log: :debug)
	plug :match
	plug :dispatch
	plug Plug.Static, at: "/home", from: :server, only: ~w(js css images robots.txt)

	get "/" do
		send_resp(conn, 200, "Hello There!")
	end

	get "/about/:user_name" do
		send_resp(conn, 200, "Hello, #{user_name}")
	end

	get "/home" do
		conn = put_resp_content_type(conn, "text/html")
		send_file(conn, 200, "priv/index.html")
	end

I need some guidance on what , I be doing wrong , your assistance will be much appreciated

Most Liked

mhanberg

mhanberg

Expert LSP Core Team
  plug :match
  plug :dispatch
  plug Plug.Static, at: "/", from: :server, only: ~w(js css images robots.txt)

must become

  plug Plug.Static, at: "/", from: :server, only: ~w(js css images robots.txt)  
  plug :match
  plug :dispatch
mhanberg

mhanberg

Expert LSP Core Team

You should use the Plug.Static plug before the :match and :dispatch plugs.

mhanberg

mhanberg

Expert LSP Core Team

Your src in the script tag should just be /js/test.js

Last Post!

hudson2010

hudson2010

Thanks @Nicd , that has worked ,now have you used extjs library with elixir before , if yes could you please share a sample project layout

Where Next?

Popular in Discussions Top

AlexMcConnell
The reason that Rails is as popular as it is is because it’s very easy for relatively inexperienced developers to get a lot of work done....
588 20070 166
New
ben-pr-p
In general I’ve been sticking to this community style guide GitHub - christopheradams/elixir_style_guide: A community driven style guide ...
New
eteeselink
Hi all, In the last days, two things happened: A blog post titled “They might never tell you it’s broken” made the rounds. It’s about ...
New
thojanssens1
It would be nice to be able to define a redirect from one route to another from the router.ex file. E.g.: redirect "/", UserController, ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
Rustixir
Hi everyone, im working on find best language/framework/system for high concurrency, high performance and stable performance after wor...
New
paulanthonywilson
I like Umbrella projects and pretty much always use them for personal Elixir stuff, especially Nerves things. But I don’t think this is ...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement