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.
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)\
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