R
R
Radist_1012015-07-29 12:50:59
Erlang
Radist_101, 2015-07-29 12:50:59

How to start cowboy server?

Hello!
Trying to run echo server from example https://github.com/robertmeta/cowboy-examples/tree...
My rebar.config
{deps, [
{cowboy, ".*", {git, " https://github. com/ninenines/cowboy.git ", {branch, "master"}}}
]}.
Download dependencies, compile. After starting the server erl -pa ebin deps/*/ebin -s echo_get I get into the shell, as I understand it, the server should work, but the server is not available on localhost:8080. Help me figure out what I'm doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Sokhatsky, 2015-09-23
@5HT

Here is an example of how to run cowboy with a single file under the application supervisor. The example is taken from the N2O documentation - Setup Web Server , this is a standard application and supervisor template in one bottle. Two static endpoints are used here, one websocket endpoint and one HTTP/1 endpoint.

-module(sample).
  -behaviour(supervisor).
  -behaviour(application).
  -export([init/1, start/2, stop/1, main/1]).

  start(_,_) -> supervisor:start_link({local,review},review,[]).
  stop(_)    -> ok.
  init([])   -> case cowboy:start_http(http,3,port(),env()) of
                     {ok, _}   -> ok;
                     {error,_} -> halt(abort,[]) end, sup().

  sup()    -> { ok, { { one_for_one, 5, 100 }, [] } }.
  port()   -> [ { port, application:get_env(n2o,port,8000)  } ].
  env()    -> [ { env, [ { dispatch, points() } ] } ].
  static() ->   { dir, "apps/sample/priv/static", mime() }.
  n2o()    ->   { dir, "deps/n2o/priv",           mime() }.
  mime()   -> [ { mimetypes, cow_mimetypes, all   } ].
  points() -> cowboy_router:compile([{'_', [

              { "/static/[...]",       n2o_static,  static()},
              { "/n2o/[...]",          n2o_static,  n2o()},
              { "/ws/[...]",           n2o_stream,  []},
              { '_',                   n2o_cowboy,  []} ]}]).

S
Sergey, 2015-07-29
@begemot_sun

Why are these examples so ancient? Now the cowboy is completely different than 4 years ago. Maybe you should use the official examples?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question