Current section
Files
Jump to
Current section
Files
src/gcourier.erl
-module(gcourier).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/gcourier.gleam").
-export([dev_server/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-file("src/gcourier.gleam", 39).
-spec check_live() -> boolean().
check_live() ->
Req@1 = case gleam@http@request:to(<<"http://localhost:8025"/utf8>>) of
{ok, Req} -> Req;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"gcourier"/utf8>>,
function => <<"check_live"/utf8>>,
line => 40,
value => _assert_fail,
start => 1025,
'end' => 1081,
pattern_start => 1036,
pattern_end => 1043})
end,
Resp = begin
_pipe = Req@1,
gleam@hackney:send(_pipe)
end,
case Resp of
{error, _} ->
gleam_erlang_ffi:sleep(1000),
check_live();
{ok, _} ->
true
end.
-file("src/gcourier.gleam", 13).
?DOC(
" Starts an SMTP server that captures outgoing mail and\n"
" displays it in the browser. By default, the server runs on localhost:1025, \n"
" and the UI runs on localhost:8025. It accepts username and password combination.\n"
).
-spec dev_server() -> nil.
dev_server() ->
Req@1 = case gleam@http@request:to(<<"http://localhost:8025"/utf8>>) of
{ok, Req} -> Req;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"gcourier"/utf8>>,
function => <<"dev_server"/utf8>>,
line => 14,
value => _assert_fail,
start => 430,
'end' => 486,
pattern_start => 441,
pattern_end => 448})
end,
Resp = begin
_pipe = Req@1,
gleam@hackney:send(_pipe)
end,
case Resp of
{error, _} ->
Binary = priv:find_bin(<<"mailpit"/utf8>>),
proc_lib:spawn_link(
fun() ->
shellout:command(
Binary,
[<<"--smtp-auth-accept-any"/utf8>>,
<<"--smtp-auth-allow-insecure"/utf8>>],
<<"."/utf8>>,
[]
)
end
),
check_live(),
nil;
{ok, _} ->
gleam_stdlib:println(
<<"Successfully started SMTP server on localhost:1025."/utf8>>
),
gleam_stdlib:println(
<<"Running web UI at http://localhost:8025."/utf8>>
),
nil
end.