mirror of
https://github.com/osm-search/Nominatim.git
synced 2024-11-27 00:49:55 +03:00
replace make serve with nominatim serve command
With the website directory now tied to the project directory instead of the build directory, it is no longer possible to use make for running the web server.
This commit is contained in:
parent
b2f8fb6201
commit
0b2abfb115
@ -117,22 +117,6 @@ if (BUILD_IMPORTER)
|
||||
${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
|
||||
#-----------------------------------------------------------------------------
|
||||
|
@ -236,7 +236,8 @@ MB. Make sure you leave enough RAM for PostgreSQL and osm2pgsql as mentioned
|
||||
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.
|
||||
|
||||
@ -244,12 +245,10 @@ Run this script to verify all required tables and indices got created successful
|
||||
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
|
||||
|
@ -11,7 +11,7 @@ import logging
|
||||
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
|
||||
@ -633,6 +633,28 @@ class QueryExport:
|
||||
|
||||
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'),
|
||||
@ -895,6 +917,7 @@ def nominatim(**kwargs):
|
||||
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)
|
||||
|
@ -89,6 +89,13 @@ def run_api_script(endpoint, project_dir, extra_env=None, phpcgi_bin=None,
|
||||
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.
|
||||
"""
|
||||
|
@ -215,6 +215,14 @@ def test_replication_update_continuous_no_change(monkeypatch, temp_db_conn, stat
|
||||
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'),
|
||||
|
Loading…
Reference in New Issue
Block a user