aboutsummaryrefslogtreecommitdiff
path: root/server/src/jchat_http_redirect.erl
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/jchat_http_redirect.erl')
-rw-r--r--server/src/jchat_http_redirect.erl17
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}.