I am building my app in sveltekit and using posthog for analytics. For proxying requests for posthog. I stored the file _redirects in the static folder.
It worked fine untill I was using the adapter-static for deploying the app. But with the app becoming more complex we needed SSR so I started using adaprer-netlify. Below is my netlify,toml
[build]
command = "npm run build"
publish = "build"
But It Stopped working after I started using edge functions. There is also a problem where this happens with sitemap.xml which is generated at build time but is not accessible by via url (https;//site.com/sitemap.xml`
I am also attaching related screenshots. If my question is unclear please point out I would Like to elaborate.
When the requests go well without a 404 error (like in the static app version it was like this).
The requests starting e/? (last) are the requests that work well in this mode. but this does not work for some reason in edge functions deployment. Also the same 404 output for sitemap.xml and robots.txt even though its there in the netlify file explorere
@shubhamandoda, as per the documentation, redirects are not supported when using an Edge Function to serve the content to the user.
This is because redirects run at the end of the request chain, which is after any Edge Functions. Because of this, you would need to move the rules you have into the Edge Function as per the documentation.
So I am using _redirects instead of putting it in netlify.toml like this.
[[redirects]]
from = "/ingest/static/*"
to = "https://us-assets.i.posthog.com/static/:splat"
host = "us-assets.i.posthog.com"
status = 200
force = true
[[redirects]]
from = "/ingest/*"
to = "https://us.i.posthog.com/:splat"
host = "us.i.posthog.com"
status = 200
force = true
Also could you also help with why the generated robots.txt isnt accessible even though if it shows in file browser.
@shubhamandoda, from my experience, redirects won’t work if the Edge Function serves a valid response to the user as it breaks the request chain. Provided the Edge Function does not handle the request that would work, but it sounds like the SvelteKit adapter is not doing that.
Your robots.txt should be listed in the manifest.json file under excludedPath. If it isn’t, it would be something to raise at GitHub · Where software is built. The manifest tells the edge function what to skip over.
Thank you for your response Sir.
I will add redirect hook manually in the Sveltekit App. And this should solve this part of the problem.
And About the second problem related to robots.txt and sitemap.xml.
I noticed that when I commit the files to git, it somehow is accessible via /robots.txt even though there is no change at all in the build output or manifest.json. I look into issue more myself and add a issue on github.