+ @contextlib.asynccontextmanager
+ async def lifespan(app: Starlette) -> AsyncIterator[Any]:
+ app.state.API = NominatimAPIAsync(project_dir, environ)
+ config = app.state.API.config
+
+ legacy_urls = config.get_bool('SERVE_LEGACY_URLS')
+ for name, func in await api_impl.get_routes(app.state.API):
+ endpoint = _wrap_endpoint(func)
+ app.routes.append(Route(f"/{name}", endpoint=endpoint))
+ if legacy_urls:
+ app.routes.append(Route(f"/{name}.php", endpoint=endpoint))
+
+ yield
+