Closed furudean closed 3 years ago
Assuming the file static/test.txt exists in the project, you should be able to fetch this file using this.fetch in a preload function as follows:
static/test.txt
this.fetch
export async function preload() { const res = await this.fetch(`/test.txt`); const text = await res.text(); if (res.status === 200) { return { text }; } else { this.error(res.status, `Expected status 200 from ${res.url}, got ${res.status}`); } };
This works in ✅ Sapper dev browser ✅ Sapper dev server ✅ Vercel hosted browser
But not in ❌ Vercel hosted server
When the preload function runs on the server when hosted on Vercel, I get put on the error page with this message:
Expected status 200 from http://127.0.0.1:3000/test.txt, got 404
Can static files not be fetched in this way on Vercel server side? Is this a known limitation? If so, is there a workaround?
Thanks!
Oops, looks like I missed the part on the README where it explicitly states how to include the files on the server.
Now that I enabled it, it works properly. Cheers!
Assuming the file
static/test.txt
exists in the project, you should be able to fetch this file usingthis.fetch
in a preload function as follows:This works in ✅ Sapper dev browser ✅ Sapper dev server ✅ Vercel hosted browser
But not in ❌ Vercel hosted server
When the preload function runs on the server when hosted on Vercel, I get put on the error page with this message:
Can static files not be fetched in this way on Vercel server side? Is this a known limitation? If so, is there a workaround?
Thanks!