-module(jchat_http_redirect). -export([init/2]). init(Req0, State) -> WebDomain = proplists:get_value(web_domain, State, "web.jchat.localhost"), Path = cowboy_req:path(Req0), % Redirect to web domain RedirectUrl = iolist_to_binary(["http://", WebDomain, Path]), Req1 = cowboy_req:reply(301, #{ <<"location">> => RedirectUrl, <<"content-type">> => <<"text/html; charset=utf-8">> }, <<"
Redirecting to ", RedirectUrl/binary, "">>, Req0), {ok, Req1, State}.