This commit is contained in:
2026-04-20 10:28:53 +03:00
parent 7e776ea6e3
commit 4224da1a22
11 changed files with 520 additions and 6 deletions

View File

@@ -1,4 +1,3 @@
%% Основной модуль приложения
-module(eventhub_app).
-behaviour(application).
@@ -7,6 +6,7 @@
start(_StartType, _StartArgs) ->
% Запускаем Mnesia
application:ensure_all_started(mnesia),
application:ensure_all_started(cowboy),
case infra_sup:start_link() of
{ok, Pid} ->
@@ -14,11 +14,43 @@ start(_StartType, _StartArgs) ->
ok = infra_mnesia:init_tables(),
ok = infra_mnesia:wait_for_tables(),
% Здесь позже запустим HTTP-сервер и другие сервисы
% Запускаем HTTP-сервер
start_http(),
{ok, Pid};
Error ->
Error
end.
stop(_State) ->
ok.
ok.
%% Internal functions
start_http() ->
Port = application:get_env(eventhub, http_port, 8080),
% Настройка маршрутов
Dispatch = cowboy_router:compile([
{'_', [
{"/health", handler_health, []},
{"/v1/register", handler_register, []},
{"/v1/login", handler_login, []},
{"/v1/refresh", handler_refresh, []},
{"/v1/user/me", handler_user_me, []}
]}
]),
% Настройка middleware
Middlewares = [
cowboy_router,
cowboy_handler
],
Env = #{dispatch => Dispatch},
cowboy:start_clear(http, [{port, Port}], #{
env => Env,
middlewares => Middlewares
}),
io:format("HTTP server started on port ~p~n", [Port]).