1defmodule FleurWeb.Endpoint do
2 use Phoenix.Endpoint, otp_app: :fleur
3
4 # The session will be stored in the cookie and signed,
5 # this means its contents can be read but not tampered with.
6 # Set :encryption_salt if you would also like to encrypt it.
1defmodule FleurWeb.Endpoint do
2 use Phoenix.Endpoint, otp_app: :fleur
3
4 # The session will be stored in the cookie and signed,
5 # this means its contents can be read but not tampered with.
6 # Set :encryption_salt if you would also like to encrypt it.
49 end
50
51 {:plug, conn, handler, opts} ->
52 %{adapter: {@connection, req}} =
53 conn
54 |> handler.call(opts)
55 |> maybe_send(handler)
56
57 {:ok, req, {handler, opts}}
58 end
59 catch
32-optional_callbacks([terminate/3]).
33
34-spec execute(Req, Env) -> {ok, Req, Env}
35 when Req::cowboy_req:req(), Env::cowboy_middleware:env().
36execute(Req, Env=#{handler := Handler, handler_opts := HandlerOpts}) ->
37 try Handler:init(Req, HandlerOpts) of
38 {ok, Req2, State} ->
39 Result = terminate(normal, Req2, State, Handler),
40 {ok, Req2, Env#{result => Result}};
41 {Mod, Req2, State} ->
42 Mod:upgrade(Req2, Env, Handler, State);
301 end.
302
303execute(_, _, []) ->
304 ok;
305execute(Req, Env, [Middleware|Tail]) ->
306 case Middleware:execute(Req, Env) of
307 {ok, Req2, Env2} ->
308 execute(Req2, Env2, Tail);
309 {suspend, Module, Function, Args} ->
310 proc_lib:hibernate(?MODULE, resume, [Env, Tail, Module, Function, Args]);
311 {stop, _Req2} ->
290%% to simplify the debugging of errors. The proc_lib library
291%% already adds the stacktrace to other types of exceptions.
292-spec request_process(cowboy_req:req(), cowboy_middleware:env(), [module()]) -> ok.
293request_process(Req, Env, Middlewares) ->
294 try
295 execute(Req, Env, Middlewares)
296 catch
297 exit:Reason={shutdown, _}:Stacktrace ->
298 erlang:raise(exit, Reason, Stacktrace);
299 exit:Reason:Stacktrace when Reason =/= normal, Reason =/= shutdown ->
300 erlang:raise(exit, {Reason, Stacktrace}, Stacktrace)