:8002 {
    log {
        output stdout
        format filter {
            wrap json
            fields {
                common_log delete
                request>headers delete
                resp_headers delete
                tls delete
            }
        }
    }

    {{ patch("mfe-caddyfile") | indent(4) }}

    @runtime_config {
        path /api/mfe_config/*
        path /api/frontend_site_config/*
    }
    handle @runtime_config {
        reverse_proxy lms:8000 {
            header_up Host {{ LMS_HOST }}
        }
    }

    {# TODO(legacy-mfe-removal): drop the is_mfe_enabled("authoring") block below. #}
    {% if is_mfe_enabled("authoring") %}
    # redirect /course-authoring to /authoring, for backward compatibility
    @course-authoring path_regexp course_authoring /course-authoring/(.*)
    redir @course-authoring /authoring/{re.course_authoring.1} permanent
    {% endif %}

    {# TODO(legacy-mfe-removal): drop the iter_legacy_paths loop below. #}
    {% for legacy_path in iter_legacy_paths() %}
    @mfe_{{ legacy_path }} {
        path /{{ legacy_path }} /{{ legacy_path }}/*
    }
    handle @mfe_{{ legacy_path }} {
        uri strip_prefix /{{ legacy_path }}
        root * /openedx/dist/{{ legacy_path }}
        try_files /{path} /index.html
        file_server
    }
    {% endfor %}

    {% if get_frontend_apps() %}
    handle {
        root * /openedx/dist/site
        try_files /{path} /index.html
        file_server
    }
    {% endif %}
}
