${PROJECT_BINARY_DIR}/nominatim)
endif()
-#-----------------------------------------------------------------------------
-# Targets for running a development webserver from the build directory.
-#-----------------------------------------------------------------------------
-
-if (BUILD_API)
- add_custom_target(serve
- php -S 127.0.0.1:8088
- WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/website
- )
-
- add_custom_target(serve-global
- php -S 0.0.0.0:8088
- WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/website
- )
-endif()
-
#-----------------------------------------------------------------------------
# Tests
#-----------------------------------------------------------------------------
above. If the system starts swapping or you are getting out-of-memory errors,
reduce the cache size or even consider using a flatnode file.
-### Verify the import
+
+### Testing the installation
Run this script to verify all required tables and indices got created successfully.
nominatim check-database
```
-### Testing the installation
-
Now you can try out your installation by running:
```sh
-make serve
+nominatim serve
```
This runs a small test server normally used for development. You can use it
from pathlib import Path
from .config import Configuration
-from .tools.exec_utils import run_legacy_script, run_api_script
+from .tools.exec_utils import run_legacy_script, run_api_script, run_php_server
from .db.connection import connect
from .db import status
from .errors import UsageError
return run_legacy_script(*params, nominatim_env=args)
+
+class AdminServe:
+ """\
+ Start a simple web server for serving the API.
+
+ This command starts the built-in PHP webserver to serve the website
+ from the current project directory. This webserver is only suitable
+ for testing and develop. Do not use it in production setups!
+
+ By the default, the webserver can be accessed at: http://127.0.0.1:8088
+ """
+
+ @staticmethod
+ def add_args(parser):
+ group = parser.add_argument_group('Server arguments')
+ group.add_argument('--server', default='127.0.0.1:8088',
+ help='The address the server will listen to.')
+
+ @staticmethod
+ def run(args):
+ run_php_server(args.server, args.project_dir / 'website')
+
STRUCTURED_QUERY = (
('street', 'housenumber and street'),
('city', 'city, town or village'),
parser.add_subcommand('refresh', UpdateRefresh)
parser.add_subcommand('export', QueryExport)
+ parser.add_subcommand('serve', AdminServe)
if kwargs.get('phpcgi_path'):
parser.add_subcommand('search', APISearch)
return 0
+def run_php_server(server_address, base_dir):
+ """ Run the built-in server from the given directory.
+ """
+ subprocess.run(['/usr/bin/env', 'php', '-S', server_address],
+ cwd=str(base_dir), check=True)
+
+
def run_osm2pgsql(options):
""" Run osm2pgsql with the given options.
"""
assert sleep_mock.last_args[0] == 60
+def test_serve_command(monkeypatch):
+ func = MockParamCapture()
+ monkeypatch.setattr(nominatim.cli, 'run_php_server', func)
+
+ call_nominatim('serve')
+
+ assert func.called == 1
+
@pytest.mark.parametrize("params", [
('search', '--query', 'new'),
('reverse', '--lat', '0', '--lon', '0'),