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

jesse
Hi everyone, I hesitated to post this here because I don’t want you to think I’m spamming, but I’ve been working on a Platform-as-a-Serv...
New
rms.mrcs
A couple of days ago I was discussing with a friend about different approaches to write microservices. He said that if he was going to w...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40082 209
New
Fl4m3Ph03n1x
Background A few days ago I was listening to The future of Elixir from Elixir Talks, with Dave Thomas (@pragdave ) and Brian Mitchell. I...
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
nunobernardes99
Hi there Elixir friends :vulcan_salute: In a recent task I was on, I needed to check in two dates which of them is the maximum and which...
New
crispinb
On reading dhh’s latest The One Person Framework it strikes me that Phoenix with LiveView is already pretty much this. However, never hav...
New

Other popular topics Top

jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40082 209
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement