diff --git a/pygeoapi/util.py b/pygeoapi/util.py index b0db50c..d7432a0 100644 --- a/pygeoapi/util.py +++ b/pygeoapi/util.py @@ -168,7 +168,7 @@ def yaml_load(fh: IO) -> dict: # # https://stackoverflow.com/a/55301129 env_matcher = re.compile( - r'.*?\$\{(?P\w+)(:-(?P[^}]+))?\}') + r'.*?\$\{(?P\w+)(:-(?P[^}]*))?\}') def env_constructor(loader, node): result = "" diff --git a/tests/pygeoapi-test-config-envvars.yml b/tests/pygeoapi-test-config-envvars.yml index f84fc79..f8b7af2 100644 --- a/tests/pygeoapi-test-config-envvars.yml +++ b/tests/pygeoapi-test-config-envvars.yml @@ -31,7 +31,7 @@ server: bind: host: 0.0.0.0 port: ${PYGEOAPI_PORT} - url: http://localhost:5000/ + url: ${PYGEOAPI_URL:-http://localhost:5000/} mimetype: application/json; charset=UTF-8 encoding: utf-8 language: en-US @@ -43,6 +43,8 @@ server: map: url: https://tile.openstreetmap.org/{z}/{x}/{y}.png attribution: '© OpenStreetMap contributors' + api_rules: # optional API design rules to which pygeoapi should adhere + url_prefix: ${PYGEOAPI_PREFIX:-} logging: level: DEBUG diff --git a/tests/test_config.py b/tests/test_config.py index 394a2bb..2b93a30 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -54,8 +54,19 @@ def test_config_envvars(): assert isinstance(config, dict) assert config['server']['bind']['port'] == 5001 + assert config['server']['url'] == 'http://localhost:5000/' assert config['metadata']['identification']['title'] == \ 'pygeoapi default instance my title' + assert config['server']['api_rules']['url_prefix'] == '' + + os.environ['PYGEOAPI_URL'] = 'https://localhost:5000' + os.environ['PYGEOAPI_PREFIX'] = 'v1' + + with open(get_test_file_path('pygeoapi-test-config-envvars.yml')) as fh: + config = yaml_load(fh) + + assert config['server']['url'] == 'https://localhost:5000' + assert config['server']['api_rules']['url_prefix'] == 'v1' os.environ.pop('PYGEOAPI_PORT')