Everytime I go to /api/v1/some-endpoint/* I would like caddy to serve a local json file from disk instead. This json file lives in /local-folder/core.json
4. Error messages and/or full log output:
ERROR http.log.error parsing browse template: parsing browse template file: open core.json: no such file or directory
5. What I already tried:
I’m very new to caddy so sorry for the ignorance. Ive tried different options like redir and also changing my folder structure but im sort of a deer in the headlights as I don’t have very much context on how to do this with caddy.
Please upgrade to v2.4.6! There’s an important security fix.
browse is not the solution for that. The browse template is what produces the UI for the “file browser”. Caddy ships with a default template which renders out the requested directory’s contents with HTML, but that template can be replaced and customized to your liking if you want to theme it etc.
If you want to just serve a particular file do a rewrite to that file, then use root + file_server to serve it.
Thank you so much for the response, but im getting an unexpected argument count for the rewrite.
watcher unable to load latest config {"config_file": "Caddyfile", "error": "adapting config using caddyfile: parsing caddyfile tokens for 'handle': Caddyfile:37 - Error during parsing: parsing caddyfile tokens for 'rewrite': Caddyfile:35 - Error during parsing: Wrong argument count or unexpected line ending after 'rewrite'"}
Yeah, that’s right. My bad. Since /core.json starts with a /, the Caddyfile parser considers that first argument to be a path matcher, and not as the actual rewrite path argument.
Does the caddy process have permissions to read that file?
Turn on the debug global option, the logs will have more details about what file_server is doing.
The leading slash means that the path is absolute. If you remove the leading slash, it’s a relative path, i.e. relative from the working directly Caddy was run from.