SvelteKit build (w/ adapter-node) 404 on newly created static files

Viewed 674

Using @sveltejs/adapter-node: 1.0.0-next.61 and @sveltejs/kit: ^1.0.0-next.225

The following issue occurs only on the build version of the app, and not on the dev server, on which it doesn't occur.

When uploading a new file, my app keeps returning 404 regarding those newly created files as though the app is blind to those. Interestingly enough, said images are found when restarting the server.

The creation request succeeds: POST REQUEST 200

The file is correctly created on the filesystem and should be loaded by the page as seen in the json response which lists all files to be loaded on the page: file exists

However, when attempting to fetch the file, the server responds with a 404 although the path to it is correct: 404

1 Answers

Actually I found two solutions but both are just workarounds to this very annoying problem.

  • The import way: that's quite tricky to configure it properly (read also this) and, overall, it becomes a pain if you need to import dynamic paths (with variables inside the import path) as it was in my case.

  • The CDN way: use the static folder as a CDN by pointing there the webserver with a dedicated (sub)domain. This way you can link assets with success as they are "external" resources (e.g. https://cdn.mysite.com/file1.png, https://cdn.mysite.com/file2.jpg).

Bonus: if you choose the CDN workaround, can be a good idea to set Externalfetch to bypass the external DNS resolution and keeping traffic internally.

Related