Skip to content

Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring

fix: remove trailing slash from GET/POST routes to prevent 307→403 redirect

Pouzor8a18ded2bcb6
diff --git a/backend/app/api/routes/canvas.py b/backend/app/api/routes/canvas.py
index 7d28770..4b0de28 100644
--- a/backend/app/api/routes/canvas.py
+++ b/backend/app/api/routes/canvas.py
@@ -12,7 +12,7 @@ from app.schemas.canvas import CanvasSaveRequest, CanvasStateResponse
router = APIRouter()
[email protected]("/", response_model=CanvasStateResponse)
[email protected]("", response_model=CanvasStateResponse)
async def load_canvas(db: AsyncSession = Depends(get_db), _: str = Depends(get_current_user)):
nodes = (await db.execute(select(Node))).scalars().all()
edges = (await db.execute(select(Edge))).scalars().all()
diff --git a/backend/app/api/routes/edges.py b/backend/app/api/routes/edges.py
index 06e2b76..c546bac 100644
--- a/backend/app/api/routes/edges.py
+++ b/backend/app/api/routes/edges.py
@@ -10,13 +10,13 @@ from app.schemas.edges import EdgeCreate, EdgeResponse, EdgeUpdate
router = APIRouter()
[email protected]("/", response_model=list[EdgeResponse])
[email protected]("", response_model=list[EdgeResponse])
async def list_edges(db: AsyncSession = Depends(get_db), _: str = Depends(get_current_user)):
result = await db.execute(select(Edge))
return result.scalars().all()
[email protected]("/", response_model=EdgeResponse, status_code=status.HTTP_201_CREATED)
[email protected]("", response_model=EdgeResponse, status_code=status.HTTP_201_CREATED)
async def create_edge(body: EdgeCreate, db: AsyncSession = Depends(get_db), _: str = Depends(get_current_user)):
edge = Edge(**body.model_dump())
db.add(edge)
diff --git a/backend/app/api/routes/nodes.py b/backend/app/api/routes/nodes.py
index b873032..d7025f1 100644
--- a/backend/app/api/routes/nodes.py
+++ b/backend/app/api/routes/nodes.py
@@ -10,13 +10,13 @@ from app.schemas.nodes import NodeCreate, NodeResponse, NodeUpdate
router = APIRouter()
[email protected]("/", response_model=list[NodeResponse])
[email protected]("", response_model=list[NodeResponse])
async def list_nodes(db: AsyncSession = Depends(get_db), _: str = Depends(get_current_user)):
result = await db.execute(select(Node))
return result.scalars().all()
[email protected]("/", response_model=NodeResponse, status_code=status.HTTP_201_CREATED)
[email protected]("", response_model=NodeResponse, status_code=status.HTTP_201_CREATED)
async def create_node(body: NodeCreate, db: AsyncSession = Depends(get_db), _: str = Depends(get_current_user)):
node = Node(**body.model_dump())
db.add(node)
diff --git a/backend/tests/test_auth.py b/backend/tests/test_auth.py
index 932b71b..355f540 100644
--- a/backend/tests/test_auth.py
+++ b/backend/tests/test_auth.py
@@ -29,7 +29,7 @@ async def test_login_wrong_username(client: AsyncClient, mock_credentials):
async def test_protected_route_requires_auth(client: AsyncClient):
- res = await client.get("/api/v1/nodes/")
+ res = await client.get("/api/v1/nodes")
assert res.status_code == 403
diff --git a/backend/tests/test_edges.py b/backend/tests/test_edges.py
index dab56d2..5ca1d1b 100644
--- a/backend/tests/test_edges.py
+++ b/backend/tests/test_edges.py
@@ -16,14 +16,14 @@ async def headers(client: AsyncClient):
@pytest.fixture
async def two_nodes(client: AsyncClient, headers: dict):
- n1 = (await client.post("/api/v1/nodes/", json={"type": "router", "label": "R1", "status": "online"}, headers=headers)).json()
- n2 = (await client.post("/api/v1/nodes/", json={"type": "switch", "label": "SW1", "status": "online"}, headers=headers)).json()
+ n1 = (await client.post("/api/v1/nodes", json={"type": "router", "label": "R1", "status": "online"}, headers=headers)).json()
+ n2 = (await client.post("/api/v1/nodes", json={"type": "switch", "label": "SW1", "status": "online"}, headers=headers)).json()
return n1["id"], n2["id"]
async def test_create_edge(client: AsyncClient, headers: dict, two_nodes):
src, tgt = two_nodes
- res = await client.post("/api/v1/edges/", json={"source": src, "target": tgt, "type": "ethernet"}, headers=headers)
+ res = await client.post("/api/v1/edges", json={"source": src, "target": tgt, "type": "ethernet"}, headers=headers)
assert res.status_code == 201
data = res.json()
assert data["source"] == src
@@ -33,22 +33,22 @@ async def test_create_edge(client: AsyncClient, headers: dict, two_nodes):
async def test_create_vlan_edge(client: AsyncClient, headers: dict, two_nodes):
src, tgt = two_nodes
- res = await client.post("/api/v1/edges/", json={"source": src, "target": tgt, "type": "vlan", "vlan_id": 20, "label": "VLAN 20"}, headers=headers)
+ res = await client.post("/api/v1/edges", json={"source": src, "target": tgt, "type": "vlan", "vlan_id": 20, "label": "VLAN 20"}, headers=headers)
assert res.status_code == 201
assert res.json()["vlan_id"] == 20
async def test_list_edges(client: AsyncClient, headers: dict, two_nodes):
src, tgt = two_nodes
- await client.post("/api/v1/edges/", json={"source": src, "target": tgt, "type": "ethernet"}, headers=headers)
- res = await client.get("/api/v1/edges/", headers=headers)
+ await client.post("/api/v1/edges", json={"source": src, "target": tgt, "type": "ethernet"}, headers=headers)
+ res = await client.get("/api/v1/edges", headers=headers)
assert res.status_code == 200
assert len(res.json()) == 1
async def test_delete_edge(client: AsyncClient, headers: dict, two_nodes):
src, tgt = two_nodes
- edge_id = (await client.post("/api/v1/edges/", json={"source": src, "target": tgt, "type": "wifi"}, headers=headers)).json()["id"]
+ edge_id = (await client.post("/api/v1/edges", json={"source": src, "target": tgt, "type": "wifi"}, headers=headers)).json()["id"]
res = await client.delete(f"/api/v1/edges/{edge_id}", headers=headers)
assert res.status_code == 204
- assert len((await client.get("/api/v1/edges/", headers=headers)).json()) == 0
+ assert len((await client.get("/api/v1/edges", headers=headers)).json()) == 0
diff --git a/backend/tests/test_nodes.py b/backend/tests/test_nodes.py
index e3a55b7..37f9f0b 100644
--- a/backend/tests/test_nodes.py
+++ b/backend/tests/test_nodes.py
@@ -15,14 +15,14 @@ async def headers(client: AsyncClient):
async def test_list_nodes_empty(client: AsyncClient, headers: dict):
- res = await client.get("/api/v1/nodes/", headers=headers)
+ res = await client.get("/api/v1/nodes", headers=headers)
assert res.status_code == 200
assert res.json() == []
async def test_create_node(client: AsyncClient, headers: dict):
payload = {"type": "server", "label": "My Server", "ip": "192.168.1.10", "status": "unknown"}
- res = await client.post("/api/v1/nodes/", json=payload, headers=headers)
+ res = await client.post("/api/v1/nodes", json=payload, headers=headers)
assert res.status_code == 201
data = res.json()
assert data["label"] == "My Server"
@@ -31,7 +31,7 @@ async def test_create_node(client: AsyncClient, headers: dict):
async def test_get_node(client: AsyncClient, headers: dict):
- create = await client.post("/api/v1/nodes/", json={"type": "router", "label": "Router", "status": "online"}, headers=headers)
+ create = await client.post("/api/v1/nodes", json={"type": "router", "label": "Router", "status": "online"}, headers=headers)
node_id = create.json()["id"]
res = await client.get(f"/api/v1/nodes/{node_id}", headers=headers)
assert res.status_code == 200
@@ -44,7 +44,7 @@ async def test_get_node_not_found(client: AsyncClient, headers: dict):
async def test_update_node(client: AsyncClient, headers: dict):
- create = await client.post("/api/v1/nodes/", json={"type": "server", "label": "Old", "status": "unknown"}, headers=headers)
+ create = await client.post("/api/v1/nodes", json={"type": "server", "label": "Old", "status": "unknown"}, headers=headers)
node_id = create.json()["id"]
res = await client.patch(f"/api/v1/nodes/{node_id}", json={"label": "New", "ip": "10.0.0.1"}, headers=headers)
assert res.status_code == 200
@@ -53,7 +53,7 @@ async def test_update_node(client: AsyncClient, headers: dict):
async def test_delete_node(client: AsyncClient, headers: dict):
- create = await client.post("/api/v1/nodes/", json={"type": "switch", "label": "Switch", "status": "unknown"}, headers=headers)
+ create = await client.post("/api/v1/nodes", json={"type": "switch", "label": "Switch", "status": "unknown"}, headers=headers)
node_id = create.json()["id"]
res = await client.delete(f"/api/v1/nodes/{node_id}", headers=headers)
assert res.status_code == 204
@@ -62,6 +62,6 @@ async def test_delete_node(client: AsyncClient, headers: dict):
async def test_list_nodes_returns_all(client: AsyncClient, headers: dict):
for i in range(3):
- await client.post("/api/v1/nodes/", json={"type": "generic", "label": f"Node {i}", "status": "unknown"}, headers=headers)
- res = await client.get("/api/v1/nodes/", headers=headers)
+ await client.post("/api/v1/nodes", json={"type": "generic", "label": f"Node {i}", "status": "unknown"}, headers=headers)
+ res = await client.get("/api/v1/nodes", headers=headers)
assert len(res.json()) == 3