This is probably something simple I don’t know. I have been through two different Cowboy/Plug on Elixir tutorials and in each case, Cowboy won’t answer on port 4000. I just get connection refused, which is what one would expect when there is no server process running. I’m doing this on a mac and I have been able to get other servers to answer on non-standard ports. Thoughts?
Well config.exs is empty but for comments and this line:
use Mix.Config
It was generated by Mix.
There does not appear to be anything in the code to specify a listening port and my understanding is that the default is 4000. I tried adding some config for the port in config.exs but all I got was syntax errors.
observer shows that cowboy and plug, among other things, are running.
On Mac we use lsof and it shows no indication that there is a listener on port 4000, and does not list any process resembling iex or erlang or cowboy or ranch or plug.
All the links you posted have something like that in the install instructions, but hex complains that there is no such package as my_???. I realize the actual package name probably does not start with my_ but I don’t see what the examples are getting at.
As for plug, I was just trying to get something working quick, following a tutorial. I think this has to be something simple/
Oh, sorry, please, ignore these instructions, they are generated by mix for every project by default. In this case, :my_cowboy is just the name of the app.
What I wanted you to see was inside /lib directories. They include working apps for different “cowboys”.
Not only /lib, actually. You might also find mix.exs useful. It defines dependencies of the app.
Ah okay, thanks. I’ll check that now. And this does not seem to be a Mac issue, I can start a python web server on port 4000 with no trouble.
Thank you for your help.
Actually those tutorials (at least one of them anyhow) are a bit old, so maybe things have changed. Here is my mix.exs file, which seems to bring the dependancies in a private:
defmodule Plugger.Mixfile do
use Mix.Project
def project do
[
app: :plugger,
version: “0.1.0”,
elixir: “~> 1.5”,
start_permanent: Mix.env == :prod,
deps: deps()
]
end
Run “mix help compile.app” to learn about applications.
def application do
[
extra_applications: [:logger, :cowboy, :plug],
mod: {Plugger.Application, }
]
end
Run “mix help deps” to learn about dependencies.
defp deps do
[
{:cowboy, “~> 1.0.2”},
{:plug, “~> 1.0”}
# {:dep_from_hexpm, “~> 0.3.0”},
# {:dep_from_git, git: “https://github.com/elixir-lang/my_dep.git”, tag: “0.1.0”},
]
end
end
Your mixfile seems fine to me. These versions of cowboy and plug should definitely work …
You don’t need to specify :extra_applications if they are already in deps, though (but it wouldn’t be a problem if you do).
I would change this mixfile to look like so
defmodule Plugger.Mixfile do
use Mix.Project
def project do
[
app: :plugger,
version: "0.1.0",
elixir: "~> 1.5",
start_permanent: Mix.env == :prod,
deps: deps()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger],
mod: {Plugger.Application, []}
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:cowboy, "~> 1.0"}, # this allows for cowboy to be 1.1
{:plug, "~> 1.0"}
]
end
end
I got it working. I just gave up, blew away what I had and started from scratch. It worked the first time through. I’ll never know why it didn’t work before but I can live with that.