thgh / vercel-sapper

Vercel builder for Sapper with SSR enabled
MIT License
189 stars 25 forks source link

this.fetch returns 404 for static files on vercel server #64

Closed furudean closed 3 years ago

furudean commented 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:

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!

furudean commented 3 years ago

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!