-module(example@app). -compile(no_auto_import). -export([main/0, app/0]). -spec main() -> {ok, nil} | {error, gleam@otp@actor:start_error()}. main() -> gleam@http@elli:become(app(), 3000). -spec app() -> fun((gleam@http@request:request(bitstring())) -> gleam@http@response:response(gleam@bit_builder:bit_builder())). app() -> Initial_context = {initial_context, <<"db_url"/utf8>>}, _pipe = bliss:use_handler( fun(Req, _) -> case gleam@http@request:path_segments(Req) of [<<"api"/utf8>> | Rest] -> api_routes(Rest); Rest@1 -> public_routes(Rest@1) end end ), _pipe@1 = example@middlewares:track(_pipe), bliss:service(_pipe@1, Initial_context). -spec public_routes(list(binary())) -> fun((gleam@http@request:request(bitstring()), example@context:initial_context()) -> {ok, gleam@http@response:response(gleam@bit_builder:bit_builder())} | {error, bliss:response_error()}). public_routes(Path) -> _pipe = bliss:use_handler(fun(_, _) -> case Path of [] -> fun example@handlers:public_home/2; [<<"version"/utf8>>] -> fun example@handlers:public_version/2; [<<"status"/utf8>>] -> fun example@handlers:public_status/2; _@1 -> fun bliss:unmatched/2 end end), bliss@middleware:cors(_pipe, <<"*"/utf8>>). -spec api_routes(list(binary())) -> fun((gleam@http@request:request(bitstring()), example@context:initial_context()) -> {ok, gleam@http@response:response(gleam@bit_builder:bit_builder())} | {error, bliss:response_error()}). api_routes(Path) -> _pipe@3 = bliss:use_handler(fun(Req, _) -> case Path of [<<"countries"/utf8>>] -> fun example@handlers:country_list/2; [<<"countries"/utf8>>, Id] -> case erlang:element(2, Req) of get -> example@handlers:country_show(Id); delete -> _pipe = example@handlers:country_delete(Id), example@middlewares:must_be_admin(_pipe); _@1 -> fun bliss:unmatched/2 end; [<<"countries"/utf8>>, Id@1, <<"cities"/utf8>>] -> example@handlers:country_city_list(Id@1); [<<"cities"/utf8>>] -> case erlang:element(2, Req) of get -> fun example@handlers:city_list/2; post -> _pipe@1 = fun example@handlers:city_create/2, example@middlewares:must_be_admin(_pipe@1); _@2 -> fun bliss:unmatched/2 end; [<<"cities"/utf8>>, Id@2] -> case erlang:element(2, Req) of get -> example@handlers:city_show(Id@2); delete -> _pipe@2 = example@handlers:city_delete(Id@2), example@middlewares:must_be_admin(_pipe@2); _@3 -> fun bliss:unmatched/2 end; [<<"languages"/utf8>>] -> fun example@handlers:language_list/2; [<<"languages"/utf8>>, Id@3] -> example@handlers:language_show(Id@3); [<<"languages"/utf8>>, Id@4, <<"countries"/utf8>>] -> example@handlers:language_countries(Id@4); _@4 -> fun bliss:unmatched/2 end end), _pipe@4 = bliss@middleware:cors(_pipe@3, <<"https://app.com"/utf8>>), example@middlewares:authenticate(_pipe@4).