SvelteKit is op deze manier geinstalleerd op het project:
npm create svelte@latest
npm install
npm i -g vercel
fetch-json.js bestand gemaakt met:
/**
* An asynchronous helper function that wraps the standard node.js fetch API.
* This function calls an API url passed as the first and mandatory parameter,
* there is an optional payload parameter to send a json object, eg. a filter.
* It then calls the API and returns the response body parsed as a json object.
* @example <caption>fetchJson as returning function using the await keyword</caption>
* const data = await fetchJson('https://api-url.com/endpoint/')
* @example <caption>fetchJson as oneliner using the then() structure.</caption>
* fetchJson('https://api-url.com/endpoint/').then((data)=>{
* // use data...
* })
* @param {string} url the api endpoint to address
* @param {object} [payload] the payload to send to the API
* @returns the response from the API endpoint parsed as a json object
*/
export default async function fetchJson(url, payload = {}) {
return await fetch(url, payload)
.then((response) => response.json())
.catch((error) => error)
}
SvelteKit is op deze manier geinstalleerd op het project:
export async function handle({ event, resolve }) { return await resolve(event, { filterSerializedResponseHeaders: (key, value) => { return key.toLowerCase() === 'content-type'; }, }); }