Working on a better router system.

This commit is contained in:
Able 2025-03-16 19:49:51 -05:00
parent 914e6a10b9
commit 3ebbab562d
4 changed files with 32 additions and 19 deletions

View file

@ -5,5 +5,7 @@
<title>Repo- ~(repo_name)</title>
</head>
<body>
<h1>~(repo_name)</h1>
</body>
</html>

View file

@ -38,27 +38,29 @@ defmodule RlRepo.ClientHandler do
Logger.info("PATH #{path}")
# Parse path
split_path = String.split(path, "/", trim: true)
split_path_length = length(split_path)
# split_path = String.split(path, "/", trim: true)
# split_path_length = length(split_path)
# TODO: Handle routing here.
case split_path_length do
1 ->
RlRepo.Router.parse_1_segment_path(split_path)
|> RlRepo.Router.route_1(request_type)
# # TODO: Handle routing here.
# case split_path_length do
# 1 ->
# RlRepo.Router.parse_1_segment_path(split_path)
# |> RlRepo.Router.route_1(request_type)
3 ->
RlRepo.Router.parse_3_segment_path(split_path)
|> RlRepo.Router.route_3(request_type)
# 3 ->
# RlRepo.Router.parse_3_segment_path(split_path)
# |> RlRepo.Router.route_3(request_type)
4 ->
RlRepo.Router.parse_4_segment_path(split_path)
|> RlRepo.Router.route_4(request_type)
# 4 ->
# RlRepo.Router.parse_4_segment_path(split_path)
# |> RlRepo.Router.route_4(request_type)
# # Note: Error handling.
# _ ->
# RlRepo.Router.status_404()
# end
Router.Api.lookup_route(path)
# Note: Error handling.
_ ->
RlRepo.Router.status_404()
end
end
def create_return_code_string(return_code) do

View file

@ -2,7 +2,11 @@ defmodule Router do
require Logger
def start() do
info = %{routes: %{}}
info = %{
routes: %{
"" => "repo"
}
}
Process.register(self(), :router)
loop_router(info)

View file

@ -1,4 +1,4 @@
defmodule Router.RouterApi do
defmodule Router.Api do
require Logger
# Search for a route.
@ -8,6 +8,11 @@ defmodule Router.RouterApi do
receive do
{:route, :exists, template} ->
Logger.info "Found route."
# {200, template}
placeholders = %{"repo_name" => "test"}
{200, "text/html", RlRepo.Template.template("repo", placeholders)}
# code
end