]> git.openstreetmap.org Git - nominatim.git/commitdiff
allow to add php-compatible endpoints
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 24 Jan 2023 20:36:45 +0000 (21:36 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Tue, 24 Jan 2023 20:39:19 +0000 (21:39 +0100)
If the new setting NOMINATIM_SERVE_LEGACY_URLS is set, the servers
expose the endpoints also with the .php suffix to ensure backwards
compatibility.

nominatim/server/falcon/server.py
nominatim/server/sanic/server.py
nominatim/server/starlette/server.py
settings/env.defaults

index 4295b3f3082d8bee3c6e91b7792bca77e9c9482d..080650e7f00911e9070e6284432d4dc2f6357a7d 100644 (file)
@@ -66,7 +66,12 @@ def get_application(project_dir: Path,
     api = NominatimAPIAsync(project_dir, environ)
 
     app = App(cors_enable=api.config.get_bool('CORS_NOACCESSCONTROL'))
+
+    legacy_urls = api.config.get_bool('SERVE_LEGACY_URLS')
     for name, func in api_impl.ROUTES:
-        app.add_route('/' + name, EndpointWrapper(func, api))
+        endpoint = EndpointWrapper(func, api)
+        app.add_route(f"/{name}", endpoint)
+        if legacy_urls:
+            app.add_route(f"/{name}.php", endpoint)
 
     return app
index 98e6b6e28b48a817a7e5bd061cf6358b2326ac94..81d62faf2853027a0415c93b98ffe66c608316a9 100644 (file)
@@ -62,7 +62,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
index dfbdc50290eae1230f36b5ba6b35ad8de6b256e1..de9a3f87965e1b53e8649e2cd2713b1b748d38f3 100644 (file)
@@ -61,8 +61,12 @@ def get_application(project_dir: Path,
     config = Configuration(project_dir, environ)
 
     routes = []
+    legacy_urls = config.get_bool('SERVE_LEGACY_URLS')
     for name, func in api_impl.ROUTES:
-        routes.append(Route(f"/{name}", endpoint=_wrap_endpoint(func)))
+        endpoint = _wrap_endpoint(func)
+        routes.append(Route(f"/{name}", endpoint=endpoint))
+        if legacy_urls:
+            routes.append(Route(f"/{name}.php", endpoint=endpoint))
 
     middleware = []
     if config.get_bool('CORS_NOACCESSCONTROL'):
index 3115f4382aacf582c5a1054e78c03130bde9f00f..84cd24f16c5a162b3974e5f72d00705ee3c17efc 100644 (file)
@@ -204,6 +204,11 @@ NOMINATIM_LOOKUP_MAX_COUNT=50
 # Set to zero to disable polygon output.
 NOMINATIM_POLYGON_OUTPUT_MAX_TYPES=1
 
+# Offer backwards compatible PHP URLs.
+# When running one of the Python enignes, they will add endpoint aliases
+# under <endpoint>.php
+NOMINATIM_SERVE_LEGACY_URLS=yes
+
 ### Log settings
 #
 # The following options allow to enable logging of API requests.