Skip to content

Instantly share code, notes, and snippets.

@masayuki038
Created July 14, 2013 18:29
Show Gist options
  • Save masayuki038/5995219 to your computer and use it in GitHub Desktop.
Save masayuki038/5995219 to your computer and use it in GitHub Desktop.
-module(toppage_handler).
-export([init/3]).
-export([handle/2]).
-export([terminate/3]).
init(_Transport, Req, []) ->
{ok, Req, undefined}.
handle(Req, State) ->
Html = get_html(),
{ok, Req2} = cowboy_req:reply(200, [{<<"content-type">>, <<"text/html">>}], Html, Req),
{ok, Req2, State}.
terminate(_Reason, _Req, _State) ->
ok.
get_html() ->
Host = econfig:get_value(erl_shib, "server", "host"),
Port = econfig:get_value(erl_shib, "server", "port"),
{ok, Cwd} = file:get_cwd(),
Filename = filename:join([Cwd, "priv", "index.html"]),
{ok, Compiled} = sgte:compile_file(Filename),
sgte:render(Compiled, [{host, Host}, {port, Port}]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment