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/3]).
-file("src\\starfruit.gleam", 9).
-spec start(integer(), binary(), binary()) -> nil.
start(Port, Cert, Key) ->
gleam_stdlib:print(
erlang:list_to_binary(
[<<"Starfruit is running on port "/utf8>>,
erlang:integer_to_binary(Port),
<<"!!"/utf8>>]
)
),
case begin
_pipe@3 = glisten:new(
fun(_) -> {nil, none} end,
fun(_, Msg, Conn) ->
Msg@2 = case Msg of
{packet, Msg@1} -> Msg@1;
_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 => 15,
value => _assert_fail,
start => 439,
'end' => 467,
pattern_start => 450,
pattern_end => 461})
end,
_ = begin
_pipe = starfruit@internal:parse_url(Msg@2),
_pipe@1 = starfruit@internal:router(_pipe),
_pipe@2 = starfruit@internal:response(_pipe@1),
starfruit@internal:senddata(_pipe@2, Conn)
end,
glisten:stop()
end
),
_pipe@4 = glisten:with_tls(_pipe@3, Cert, Key),
_pipe@5 = glisten:bind(_pipe@4, <<"0.0.0.0"/utf8>>),
glisten:start(_pipe@5, Port)
end of
{ok, _} -> nil;
_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 => 13,
value => _assert_fail@1,
start => 344,
'end' => 762,
pattern_start => 355,
pattern_end => 360})
end,
gleam_erlang_ffi:sleep_forever().