diff options
author | Calvin Morrison <calvin@pobox.com> | 2025-09-03 21:15:36 -0400 |
---|---|---|
committer | Calvin Morrison <calvin@pobox.com> | 2025-09-03 21:15:36 -0400 |
commit | 49fa5aa2a127bdf8924d02bf77e5086b39c7a447 (patch) | |
tree | 61d86a7705dacc9fddccc29fa79d075d83ab8059 /server/src/jchat_http_redirect.erl |
Diffstat (limited to 'server/src/jchat_http_redirect.erl')
-rw-r--r-- | server/src/jchat_http_redirect.erl | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/server/src/jchat_http_redirect.erl b/server/src/jchat_http_redirect.erl new file mode 100644 index 0000000..9ad5a5e --- /dev/null +++ b/server/src/jchat_http_redirect.erl @@ -0,0 +1,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}. |