Skip to content

feat: add public URLs and typed custom config #460

Closed

Description

@uniqueg

FOCA apps need their public URL, e.g., for Location headers of created resources or links in responses, and behind a reverse proxy or ingress it differs from the URL the app sees (scheme, host, port and a path prefix of the proxy). FOCA has no setting for it, so each app adds its own custom config (e.g., custom.endpoints.service with url_prefix, external_host, external_port and api_path) and code. Apps also each write a typed getter for their custom config, as FOCA keeps it as an untyped extra field (get_config().model_extra["custom"]). elixir-cloud-aai/cloud-registry, the template for FOCA apps, has both in cloud_registry/utils.py: get_custom_config(), get_public_url(path) and _format_host() (tests in tests/test_utils.py).

Move them into FOCA, generically:

  • server.public_url: str | None = None (new): absolute http/https URL of the app as clients see it, including any path prefix of a proxy, e.g., https://api.example.org/my-app/. Validated and normalized with foca.utils.urls (check_url(), normalize_url(); host in URL form, e.g., bracketed IPv6 addresses with encoded zone IDs, so _format_host() is not needed); no query or fragment. The foca-common chart's tests already set custom.public_url from hostName; a chart helper for server.public_url is a possible follow-up.
  • foca.utils.urls.get_public_url(path: str = "") -> str: in a request context, public_url, followed by the app's root path (request.script_root) and path, percent-encoded (the prefix of public_url as configured), without trailing slash unless it is the host's root, as in cloud-registry. If public_url is not set, it raises RuntimeError, rather than building the URL from the request's Host and X-Forwarded-* headers, which clients control unless a proxy sets them.
  • foca.get_custom_config(model: type[T]) -> T (in foca.config.access, exported from foca like get_config()): the custom config of the current app, if it is an instance of model; otherwise RuntimeError, hinting that custom_config_model must be the model's full module path (a model imported under another module path is another class).
  • Backwards compatible: new, optional setting and functions; nothing changes for apps that don't use them.
  • Docs: docs/configuration/server.md (public_url, with a proxy example), docs/configuration/custom.md (get_custom_config()), docs/utilities.md (get_public_url()), and the option in templates/config.yaml.

Follow-up in cloud-registry (separate issue there): replace custom.endpoints.service with server.public_url (a breaking config change there, with its own upgrade notes and chart change), and delete get_custom_config(), get_public_url() and _format_host() from cloud_registry/utils.py.

Open question for the maintainer: should get_public_url() fall back to the request URL (as Flask's url_for(..., _external=True) does) when public_url is not set? This issue raises an error instead, as that is the safe choice and a fallback can be added later.

Acceptance criteria

  • server.public_url is validated (absolute http/https URL, no query or fragment) and normalized.
  • get_public_url() builds URLs as in cloud-registry's tests (path prefix, root path, percent-encoding, trailing slash, IPv6 hosts) and raises without public_url.
  • get_custom_config() returns the typed custom config and raises for a missing or other model.
  • Tests at 100% coverage; docs and templates/config.yaml updated; the strict docs build passes.
  • No migration note needed (opt-in); the changelog mentions it.

Activity

  1. added this to the v0.18.0 milestone on Oct 24, 2026
  2. added
    priority: medium
    status: triage
    type: feature
    workload: hours
    status: in progress
    and removed
    status: triage
    on Oct 24, 2026
  3. removed
    status: in progress
    on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: mediumtype: featureworkload: hours

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions