Using SvelteKit Endpoints in Netlify
Hey! Thanks for stopping by! Just a word of warning, this post
is 5 years old, wow! If there's technical information in here it's more than likely out
of date.
I’ve been using Netlify recently to make a project that uses endpoints. Unlike with Vercel where you can use the endpoint to fetch the data dynamically Netlify needs to statically generate the data.
There’s some SvelteKit prerender settings that need configuration
here’s what I set in the svelte.config.js file:
import adapter from '@sveltejs/adapter-static'
import preprocess from 'svelte-preprocess'
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
// hydrate the <div id="svelte"> element in src/app.html
target: '#svelte',
adapter: adapter(),
prerender: {
crawl: true,
enabled: true,
onError: 'continue',
pages: ['*'],
},
},
preprocess: [
preprocess({
postcss: true,
}),
],
}
export default config Also for the pages that use the endpoint I’ve added the following to any page that uses an endpoint:
<script context="module">
export const prerender = true
// rest of the code for the endpoint
</script>There's a reactions leaderboard you can check out too.
Sign up for the newsletter
Want to keep up to date with what I'm working on?
Join other developers and sign up for the newsletter.
I care about the protection of your data. Read the Privacy Policy for more info.