Packages
mist
0.8.0
6.0.3
6.0.2
6.0.1
6.0.0
5.0.4
5.0.3
5.0.2
5.0.1
5.0.0
5.0.0-rc1
4.0.7
4.0.6
4.0.5
4.0.4
4.0.3
4.0.2
4.0.1
4.0.0
3.0.0
2.0.0
1.2.0
1.1.0
1.0.0
1.0.0-rc3
1.0.0-rc2
1.0.0-rc1
0.17.0
0.15.0
0.14.3
0.14.2
0.14.1
0.14.0
0.13.2
0.13.1
0.13.0
0.12.0
0.11.0
0.10.0
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.8.3
0.8.2
0.8.1
0.8.0
0.7.1
0.7.0
0.6.1
0.6.0
0.5.2
0.5.1
0.5.0
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.3
0.3.2
0.3.1
0.3.0
0.2.1
0.2.0
0.1.3
a misty Gleam web server
Current section
Files
Jump to
Current section
Files
src/mist.erl
-module(mist).
-compile(no_auto_import).
-export([run_service/3, serve/2, main/0]).
-spec run_service(
integer(),
fun((gleam@http@request:request(bitstring())) -> gleam@http@response:response(gleam@bit_builder:bit_builder())),
integer()
) -> {ok, nil} | {error, glisten:start_error()}.
run_service(Port, Handler, Max_body_limit) ->
_pipe = Handler,
_pipe@1 = mist@handler:with(_pipe, Max_body_limit),
_pipe@2 = glisten@tcp:acceptor_pool_with_data(
_pipe@1,
mist@handler:new_state()
),
glisten:serve(Port, _pipe@2).
-spec serve(
integer(),
fun((glisten@tcp:handler_message(), glisten@tcp:loop_state(mist@handler:state())) -> gleam@otp@actor:next(glisten@tcp:loop_state(mist@handler:state())))
) -> {ok, nil} | {error, glisten:start_error()}.
serve(Port, Handler) ->
_pipe = Handler,
_pipe@1 = glisten@tcp:acceptor_pool_with_data(
_pipe,
mist@handler:new_state()
),
glisten:serve(Port, _pipe@1).
-spec main() -> nil.
main() ->
{ok, _@3} = case serve(
8080,
mist@handler:with_func(
fun(Req) -> case gleam@http@request:path_segments(Req) of
[<<"static"/utf8>> | Path] ->
File_path = begin
_pipe = Path,
_pipe@1 = gleam@string:join(_pipe, <<"/"/utf8>>),
_pipe@2 = gleam@string:append(<<"/"/utf8>>, _pipe@1),
gleam@bit_string:from_string(_pipe@2)
end,
Size = mist@file:size(File_path),
{ok, Fd@1} = case mist@file:open(File_path) of
{ok, Fd} -> {ok, Fd};
_try ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try,
module => <<"mist"/utf8>>,
function => <<"main"/utf8>>,
line => 56})
end,
_pipe@3 = gleam@http@response:new(200),
_pipe@4 = gleam@http@response:set_body(
_pipe@3,
{file_body,
Fd@1,
gleam@int:to_string(Size),
0,
Size}
),
{response, _pipe@4};
_@1 ->
_pipe@5 = gleam@http@response:new(404),
_pipe@6 = gleam@http@response:set_body(
_pipe@5,
{bit_builder_body, gleam@bit_builder:new()}
),
{response, _pipe@6}
end end
)
) of
{ok, _@2} -> {ok, _@2};
_try@1 ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try@1,
module => <<"mist"/utf8>>,
function => <<"main"/utf8>>,
line => 43})
end,
gleam@erlang@process:sleep_forever().