aboutsummaryrefslogtreecommitdiff
path: root/server/src/jchat_http_redirect.erl
blob: 9ad5a5ec279e207e2738152ea7c5f761c8a985c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-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">>
    }, <<"<html><body>Redirecting to <a href=\"", RedirectUrl/binary, "\">", RedirectUrl/binary, "</a></body></html>">>, Req0),
    
    {ok, Req1, State}.