What you have should/will work, but will by default redirect using a 301 (see documentation) which is a permanent redirect.
Ideally, you would use
/api/* /.netlify/functions/:splat 200
which does not redirect but returns the content from the function (without the path/address changing.)
Are you still seeing a 404? Are the functions getting loaded when netlify dev starts e.g.
◈ Loaded function print-headers (http://localhost:8888/.netlify/functions/print-headers).
◈ Loaded function rebuild-site (http://localhost:8888/.netlify/functions/rebuild-site).
◈ Loaded function redirector (http://localhost:8888/.netlify/functions/redirector).
◈ Functions server is listening on 50870
Yes, I’m seeing the function getting loaded
$ ntl dev
◈ Netlify Dev ◈
◈ Injected build settings env var: MY_SECRET
◈ Ignored general context env var: LANG (defined in process)
◈ Loaded function hello-world.
◈ Functions server is listening on 45113
◈ Starting Netlify Dev with Astro
Interesting, so the redirect is working for you locally. Maybe its an OS issue? I think you’re seeing ‘undefined’ because the message includes an environment variable that isn’t present in your build/deploy environment.
Sorry – missed that at first. Thanks – I have an old mac I can test with. I’ll see if that makes a difference. I’ll also try cloning my repo to a new directory and trying again, though it should be in sync with the github repo. If it turns out to be an OS issue, I’ll go ahead and report it. Thanks again!!
I don’t think it’s an OS issue. I think it’s something to do with directory linking.
I cloned to a new directory and ran npm install then ntl dev then browsed to localhost:8888/api/hello-world and got “hello world! I have a undefined” – so the redirect worked – but then when I ran ntl link and selected the site id, then restarted with ntl dev, the redirect broke again.
localhost:8888/api/hello-world gives “404 not found” even though localhost:8888/.netlify/functions/hello-world gives me “hello world! I have a super secret”.