ChadK
ChadK
CDCloudflare Developers
Created by Nemanja02 on 12/22/2024 in #workers-help
Svelte Kit Deployment
I have a SvelteKit app deployed to Cloudflare Pages not Cloudflare Workers, but here are a few places to start: 1) I recall having to be explicit about routes in svelte.config.js. Note the routes object in the docs: https://svelte.dev/docs/kit/adapter-cloudflare#Usage 2) Since this is working locally but not on CF, I'd recommend using hooks.server.ts to try to get to the heart of the issue, e.g.
export const handleError: HandleServerError = async ({ error }) => {
// Capture "window is undefined" errors likely caused by a SSR-generated component using a browser API, e.g. Chart.js
if (error instanceof ReferenceError && error.message === 'window is not defined') {
console.error('Window Reference Error:', error.stack);
}
// Capture all other errors
if (error) {
console.log(error);
}
return {
message: 'Internal Server Error',
};
};
export const handleError: HandleServerError = async ({ error }) => {
// Capture "window is undefined" errors likely caused by a SSR-generated component using a browser API, e.g. Chart.js
if (error instanceof ReferenceError && error.message === 'window is not defined') {
console.error('Window Reference Error:', error.stack);
}
// Capture all other errors
if (error) {
console.log(error);
}
return {
message: 'Internal Server Error',
};
};
3) Keep in mind the Worker environment is not a full Node environment and has size limits. 4) This is unlikely to be your error since it works locally, but one thing that tripped me up early on was NOT wrapping third party scripts in an onMount. SvelteKit is SSR happy which is great, but just remember anything looking for a browser API on the server will throw a 500 error. Good luck!
2 replies
CDCloudflare Developers
Created by ChadK on 12/13/2024 in #workers-help
Gut check: For 200k page Jekyll site, Workers => R2, yeah?
Thanks, it's been a fun project. I appreciate the creative solutions. I've got a POC running using the older Workers Sites product. https://developers.cloudflare.com/workers/configuration/sites/start-from-existing/ I haven't tested syncing the full site yet, but looks promising. It'll put me over the free tier, but for $5 + a bit for the KV storage excess it's well worth it imho.
6 replies
CDCloudflare Developers
Created by ChadK on 12/13/2024 in #workers-help
Gut check: For 200k page Jekyll site, Workers => R2, yeah?
Happy to share the code. It's an open source project for nonprofits - been around since 2016. The Jekyll site has 110k content pages and 120k HTML redirects. The redirects are the main reason for moving off Github Pages. Moving to Cloudflare, where the rebuilt site will reside, opens up new redirect options and should aid in an incremental transition to the new site.
6 replies