For Workers & Pages, what is the name of the domain?
https://b152888c.new-portfolio-1lc.pages.dev/
What is the error number?
404
What is the error message?
File not found for slug: 2023-08-01-animperium
What is the issue or error you’re encountering
I’m unable to access the HTML static assets generated by the sveltekit adapter. Non-HTML files seem to work fine.
What steps have you taken to resolve the issue?
I’ve tried a couple things. First, the underlying code is this:
export const load: PageServerLoad = async ({ params, fetch, url }) => {
const { slug } = params;
// Fetch the blog post HTML file instead of using fs
let response = await fetch(`${url.origin}/blog-pages/${slug}.html`);
if (!response.ok) {
error(404, { message: `File not found for slug: ${slug}` });
}
const htmlContent = await response.text();
const blogData = await supabase
.rpc("get_metadata", { slug: slug })
.select().single();
return { htmlContent, ...(blogData.data) };
};
The ${url.origin}
in the fetch is new, and a suggestion from ChatGPT. Did not resolve the issue. I also tried to check supabase if the database was actually being accessed. It was, so that wasn’t the cause of the issue. I made sure the key and url for supabase were correct multiple times.
The issue also does not occur on my laptop when testing locally, neither in dev mode or preview mode. However, it does arise in both preview and production mode when run from cloudflare, ie. the deployed site, directly. My laptop is able to locally access the static files just fine.
I tried to go to the other static files like osama.webp or images/dark-mode.webp, but those worked fine. It turns out, it is specifically HTML pages that don’t work.
Note that the static files do not have conflicting paths with the blog post URLs, I’ve run into that issue before, and that’s the whole idea of making sure the static directory was called ‘blog-pages’ rather than ‘blog’, which would have caused the problem.
What are the steps to reproduce the issue?
It’s a fairly complicated issue, but apparently creating a new Sveltekit project with an HTML static asset would reproduce it. I integrated the project from GitHub onto cloudflare pages.
To access the issue on the site, just click any of the blog posts to run into the 404 error.