X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/e490a30a4a926a55543fe3222e808233069b869e..1facfd019b3e0c86b3cfb1a25ae0837cce4bdcae:/nominatim/server/sanic/server.py?ds=inline diff --git a/nominatim/server/sanic/server.py b/nominatim/server/sanic/server.py index 98e6b6e2..a2379501 100644 --- a/nominatim/server/sanic/server.py +++ b/nominatim/server/sanic/server.py @@ -16,6 +16,7 @@ from sanic.response import text as TextResponse from nominatim.api import NominatimAPIAsync import nominatim.api.v1 as api_impl +from nominatim.config import Configuration class ParamWrapper(api_impl.ASGIAdaptor): """ Adaptor class for server glue to Sanic framework. @@ -33,13 +34,16 @@ class ParamWrapper(api_impl.ASGIAdaptor): return cast(Optional[str], self.request.headers.get(name, default)) - def error(self, msg: str) -> SanicException: - return SanicException(msg, status_code=400) + def error(self, msg: str, status: int = 400) -> SanicException: + return SanicException(msg, status_code=status) - def create_response(self, status: int, output: str, - content_type: str) -> HTTPResponse: - return TextResponse(output, status=status, content_type=content_type) + def create_response(self, status: int, output: str) -> HTTPResponse: + return TextResponse(output, status=status, content_type=self.content_type) + + + def config(self) -> Configuration: + return cast(Configuration, self.request.app.ctx.api.config) def _wrap_endpoint(func: api_impl.EndpointFunc)\ @@ -62,7 +66,11 @@ def get_application(project_dir: Path, from sanic_cors import CORS # pylint: disable=import-outside-toplevel CORS(app) + legacy_urls = app.ctx.api.config.get_bool('SERVE_LEGACY_URLS') for name, func in api_impl.ROUTES: - app.add_route(_wrap_endpoint(func), f"/{name}", name=f"v1_{name}_simple") + endpoint = _wrap_endpoint(func) + app.add_route(endpoint, f"/{name}", name=f"v1_{name}_simple") + if legacy_urls: + app.add_route(endpoint, f"/{name}.php", name=f"v1_{name}_legacy") return app