Try_files and reverse_proxy

For this, you’ll want to use a matcher that excludes /api*.

 familiengrondahl.dk {
    root C:\websites\grondahl-frontend

    reverse_proxy /api* localhost:5000

    @notAPI {
        not {
            path /api*
        }
        file {
            try_files {path} {path}/ /index.html?{query}
        }
    }
    rewrite @notAPI {http.matchers.file.relative}

    file_server
}

As an explanation: the try_files directive is special in that it’s a shortcut for rewrite with a try_files matcher; it doesn’t support matchers because it itself involves a matcher internally. So instead, we need to explicitly use the expanded form of try_files, i.e. using a rewrite.

1 Like