I’m trying to create a router where everything is in a collection of routes (similar to how I do my routes in expressjs). But it doesn’t seem to work. Can anyone help me out?
# routes.ex
defmodule Api.API.Router do
use Raxx.Router
alias Api.API.Actions
def stack(config) do
Raxx.Stack.new(
[
# Add global middleware here.
],
{__MODULE__, config}
)
end
section([{Raxx.Logger, Raxx.Logger.setup(level: :info)}], [
{%{path: []}, Actions.RootRoute},
{%{path: ["users"]}, Actions.Users}
])
section([{Raxx.Logger, Raxx.Logger.setup(level: :debug)}], [
{_, Actions.NotFound}
])
end
# controllers/users.ex
defmodule Api.API.Actions.Users do
use Raxx.SimpleServer
alias Api.API
@impl Raxx.SimpleServer
def handle_request(_request = %{method: :GET}, _state) do
response(:ok)
|> API.set_json_payload(%{path: "root"})
end
def handle_request(_request = %{method: :GET, path: ["test"]}, _state) do
response(:ok)
|> API.set_json_payload(%{path: "test"})
end
def handle_request(_request = %{method: :GET, path: ["testo"]}, _state) do
response(:ok)
|> API.set_json_payload(%{path: "testo"})
end
end
/users/
is normal and works fine, but I get a not found error when I try to access /users/test
or /users/testo
Thanks in advance!