<div dir="ltr">No, I don't think so, it's not quite as flexible as something like Express. But you can check the Req path in your middleware.</div><div class="gmail_extra"><br><div class="gmail_quote">On 7 December 2015 at 10:39, avinash D'silva <span dir="ltr"><<a href="mailto:evnix.com@gmail.com" target="_blank">evnix.com@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">wow!! thanks!<div><br></div><div>It worked perfectly.</div><div><br></div><div><br></div><div>is there a way to assign the middleware to specific routes? currently all the public routes are blocked due to the login middleware.</div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Mon, Dec 7, 2015 at 3:08 PM, Graham Hay <span dir="ltr"><<a href="mailto:grahamrhay@gmail.com" target="_blank">grahamrhay@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">You might be able to do something with a cowboy middleware:<div><br></div><div><a href="http://ninenines.eu/docs/en/cowboy/HEAD/guide/middlewares/" target="_blank">http://ninenines.eu/docs/en/cowboy/HEAD/guide/middlewares/</a><br></div><div><br></div><div>Or, failing that, you could just extract that case to a module somewhere,</div><div>and pass in "do something here" as a fun.</div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On 7 December 2015 at 09:03, avinash D'silva <span dir="ltr"><<a href="mailto:evnix.com@gmail.com" target="_blank">evnix.com@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr"><div>Hi,</div><div><br></div><div><br></div><div>I am using cowboy+cowboy_session for building websites. </div><div><br></div><div>each route has something similar as shown below:</div><div><br></div><div><br></div><div><div>-module(get_pageX).</div><div>-behaviour(cowboy_http_handler).</div><div><br></div><div>-export([init/3]).</div><div>-export([handle/2]).</div><div>-export([terminate/3]).</div><div><br></div><div>-record(state, {</div><div>}).</div><div><br></div><div>init(_, Req, _Opts) -></div><div><span style="white-space:pre-wrap"> </span>{ok, Req, #state{}}.</div><div><br></div><div>handle(Req, State=#state{}) -></div><div><br></div><div> </div><div><br></div><div> case cowboy_session:get("loggedin", Req) of</div><div><br></div><div> true -> </div><div> #do something here</div><div> </div><div> _ -></div><div> #not logged in.</div><div><br></div><div> end,</div><div><br></div><div><br></div><div><br></div><div><span style="white-space:pre-wrap"> </span>{ok, ReqFinal} = cowboy_req:reply(200,</div><div><span style="white-space:pre-wrap"> </span>[{<<"content-type">>, <<"text/html">>}],</div><div> <span style="white-space:pre-wrap"> <<"Some response">></span>,</div><div> <span style="white-space:pre-wrap"> </span>Req),</div><div><br></div><div><span style="white-space:pre-wrap"> </span>{ok, ReqFinal, State}.</div><div><br></div><div>terminate(_Reason, _Req, _State) -></div><div><span style="white-space:pre-wrap"> </span>ok.</div></div><div><br></div><div><br></div><div>The above CASE(code) is repeated for every route to check if the user is logged in, is there a better way to organize this?</div><div><br></div><div>what I am looking for is a way to check if the user is logged in and if not, redirect to login route.</div><div><br></div><div><br></div><div>PS: I am new to Erlang</div><div><br></div><div><br></div><div>Regards,</div><div>Avinash D' Silva <br></div><div><br></div><div><br></div>
</div>
<br></div></div><span>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></span></blockquote></div><br></div></div>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div>Powered B<span></span><span></span>y <a href="http://codologic.com" target="_blank">codologic</a></div>
</font></span></div>
</blockquote></div><br></div>