# SPDX-FileCopyrightText: 2026 Bart Broere # SPDX-License-Identifier: GPL-3.0-or-later """The Neo4j discovery document, served over HTTP on both the browser and the Bolt port.""" import json import os from .backend import NEO4J_VERSION def discovery_document(headers, bolt_port) -> bytes: """The JSON Neo4j serves at ``/`` so clients can find the Bolt endpoint.""" host = headers.get("host") or "localhost" if host.startswith("["): # IPv6 literal, e.g. [::1]:7474 host = host[:host.index("]") + 1] else: host = host.split(":", 1)[0] port = os.environ.get("PEO_ADVERTISED_BOLT_PORT", str(bolt_port)) return json.dumps({ "bolt_routing": f"neo4j://{host}:{port}", "bolt_direct": f"bolt://{host}:{port}", "neo4j_version": NEO4J_VERSION, "neo4j_edition": "community", }).encode()