MCPcopy Create free account
hub / github.com/cppla/ServerStatus / route

Method route

server/manage_api.py:337–449  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

335 self.send_json(err.status, payload)
336
337 def route(self):
338 parsed = urlparse(self.path)
339 path = parsed.path.rstrip("/") or "/"
340 method = self.command.upper()
341 if method == "OPTIONS":
342 self.send_response(204)
343 self.end_headers()
344 return
345 try:
346 if path == "/api/health" and method == "GET":
347 pid = get_sergate_pid()
348 self.send_json(200, {
349 "ok": True,
350 "enabled": bool(ADMIN_TOKEN),
351 "sergate": {"running": bool(pid), "pid": pid},
352 "configPath": CONFIG_PATH,
353 })
354 return
355 if path == "/api/schema" and method == "GET":
356 self.send_json(200, {"ok": True, "schema": api_schema()})
357 return
358 self.require_auth()
359 if path == "/api/config":
360 if method == "GET":
361 self.send_json(200, {"ok": True, "config": load_config()})
362 return
363 if method == "PUT":
364 config = read_body(self)
365 config, pid = write_and_reload(config)
366 self.send_json(200, {"ok": True, "reloaded": True, "pid": pid, "config": config})
367 return
368 if path == "/api/servers":
369 if method == "GET":
370 config = load_config()
371 self.send_json(200, {"ok": True, "servers": config.get("servers", [])})
372 return
373 if method == "POST":
374 server = validate_server(read_body(self))
375 config = load_config()
376 if find_server(config, server["username"])[1] is not None:
377 raise ApiError(409, "server username already exists", {"username": server["username"]})
378 config.setdefault("servers", []).append(server)
379 config, pid = write_and_reload(config)
380 self.send_json(201, {"ok": True, "server": server, "reloaded": True, "pid": pid, "config": config})
381 return
382 if path.startswith("/api/servers/"):
383 username = unquote(path[len("/api/servers/"):])
384 if not username:
385 raise ApiError(400, "username is required")
386 config = load_config()
387 index, existing = find_server(config, username)
388 if index < 0:
389 raise ApiError(404, "server was not found", {"username": username})
390 if method == "PUT":
391 server = validate_server(read_body(self))
392 if server["username"] != username and find_server(config, server["username"])[1] is not None:
393 raise ApiError(409, "server username already exists", {"username": server["username"]})
394 config["servers"][index] = server

Callers 5

do_GETMethod · 0.95
do_POSTMethod · 0.95
do_PUTMethod · 0.95
do_DELETEMethod · 0.95
do_OPTIONSMethod · 0.95

Calls 14

end_headersMethod · 0.95
send_jsonMethod · 0.95
require_authMethod · 0.95
send_error_jsonMethod · 0.95
get_sergate_pidFunction · 0.85
api_schemaFunction · 0.85
load_configFunction · 0.85
read_bodyFunction · 0.85
write_and_reloadFunction · 0.85
validate_serverFunction · 0.85
find_serverFunction · 0.85
ApiErrorClass · 0.85

Tested by

no test coverage detected