#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2023 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Server implementation using the starlette webserver framework.
"""
-from typing import Any, Type
+from typing import Any, Type, Optional, Mapping
from pathlib import Path
from starlette.applications import Starlette
from starlette.responses import Response
from starlette.requests import Request
-from nominatim.api import NominatimAPIAsync
-from nominatim.apicmd.status import StatusResult
+from nominatim.api import NominatimAPIAsync, StatusResult
import nominatim.result_formatter.v1 as formatting
CONTENT_TYPE = {
"""
parse_format(request, StatusResult, 'text')
result = await request.app.state.API.status()
- return format_response(request, result)
+ response = format_response(request, result)
+
+ if request.state.format == 'text' and result.status:
+ response.status_code = 500
+
+ return response
V1_ROUTES = [
Route('/status', endpoint=on_status)
]
-def get_application(project_dir: Path) -> Starlette:
+def get_application(project_dir: Path,
+ environ: Optional[Mapping[str, str]] = None) -> Starlette:
""" Create a Nominatim falcon ASGI application.
"""
app = Starlette(debug=True, routes=V1_ROUTES)
- app.state.API = NominatimAPIAsync(project_dir)
+ app.state.API = NominatimAPIAsync(project_dir, environ)
return app