Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined Function: init/1 #81

Closed
rizafahmi opened this issue Aug 17, 2014 · 4 comments
Closed

Undefined Function: init/1 #81

rizafahmi opened this issue Aug 17, 2014 · 4 comments

Comments

@rizafahmi
Copy link

Trying to use plug (0.5.3) using cowboy (1.0.0) with Elixir 0.15.0 and did hello world in the doc but getting this error:

Running with Cowboy on http://localhost:4000
== Compilation error on file lib/plug_try.ex ==

** (UndefinedFunctionError) undefined function: PlugTry.init/1
PlugTry.init([])
lib/plug/adapters/cowboy.ex:158: Plug.Adapters.Cowboy.dispatch_for/2
lib/plug/adapters/cowboy.ex:36: Plug.Adapters.Cowboy.args/4
lib/plug/adapters/cowboy.ex:125: Plug.Adapters.Cowboy.run/4
(stdlib) erl_eval.erl:657: :erl_eval.do_apply/6

@josevalim
Copy link
Member

Have you defined the init/1 function in your plug? If yes, can you please post its source?

@rizafahmi
Copy link
Author

defmodule PlugTry do
  import Plug.Conn

  def init(options) do
    options
  end

  def call(conn, _opts) do
    conn
    |> put_res_content_type("text/plain")
    |> send_resp(200, "Hello, world!")
  end

  IO.puts "Running with Cowboy on http://localhost:4000"
  Plug.Adapters.Cowboy.http PlugTry, []
end

@josevalim
Copy link
Member

You need to move the last two lines to outside the module, after the module is defined, otherwise it won't indeed find the functions!

@rizafahmi
Copy link
Author

My bad :)

Thanks @josevalim !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants