Packages

starfruit is a minimal gemini protocol static content server!

Current section

Files

Jump to
starfruit src starfruit.erl
Raw

src/starfruit.erl

-module(starfruit).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src\\starfruit.gleam").
-export([start/5]).
-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\\starfruit.gleam", 11).
?DOC(" This is all you need!\n").
-spec start(integer(), binary(), binary(), boolean(), binary()) -> nil.
start(Port, Cert, Key, Loopback, Hostname) ->
gleam_stdlib:print(
erlang:list_to_binary(
[<<"⋆✴︎˚。⋆ Starfruit is listening on port "/utf8>>,
erlang:integer_to_binary(Port),
<<"!! ⋆。˚✴︎⋆\n"/utf8>>]
)
),
case begin
_pipe@3 = glisten:new(
fun(_) -> {nil, none} end,
fun(_, Msg, Conn) ->
Source@1 = case glisten:get_connection_info(Conn) of
{ok, Source} -> Source;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"starfruit"/utf8>>,
function => <<"start"/utf8>>,
line => 27,
value => _assert_fail,
start => 633,
'end' => 690,
pattern_start => 644,
pattern_end => 654})
end,
case erlang:element(3, Conn) of
tcp ->
glisten:stop();
ssl ->
Msg@2 = case Msg of
{packet, Msg@1} -> Msg@1;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"starfruit"/utf8>>,
function => <<"start"/utf8>>,
line => 35,
value => _assert_fail@1,
start => 881,
'end' => 909,
pattern_start => 892,
pattern_end => 903})
end,
_ = begin
_pipe = starfruit@internal:parse_url(
Msg@2,
Port,
Hostname,
erlang:element(3, Source@1)
),
_pipe@1 = starfruit@internal:router(_pipe),
_pipe@2 = starfruit@internal:response(_pipe@1),
starfruit@internal:senddata(_pipe@2, Conn)
end,
glisten:stop()
end
end
),
_pipe@4 = glisten:with_tls(_pipe@3, Cert, Key),
_pipe@5 = starfruit@internal:bind(_pipe@4, Loopback),
glisten:start(_pipe@5, Port)
end of
{ok, _} -> nil;
_assert_fail@2 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"starfruit"/utf8>>,
function => <<"start"/utf8>>,
line => 25,
value => _assert_fail@2,
start => 538,
'end' => 1283,
pattern_start => 549,
pattern_end => 554})
end,
gleam_erlang_ffi:sleep_forever().