Use Swell REST API for fetching products

This commit is contained in:
2022-09-18 17:10:06 +02:00
parent 2393d28597
commit c7b67b909c
4 changed files with 24 additions and 39 deletions

View File

@@ -1,7 +1,8 @@
import { error } from '@sveltejs/kit'
import type { PageServerLoad } from './$types'
import { fetchAPI } from '$utils/api'
import { initSwell, getProducts } from '$utils/functions/shop'
import { PUBLIC_SWELL_STORE_ID } from '$env/static/public'
import { SWELL_API_TOKEN, SWELL_API_ENDPOINT } from '$env/static/private'
export const load: PageServerLoad = async () => {
try {
@@ -55,8 +56,12 @@ export const load: PageServerLoad = async () => {
/**
* Get products data from Swell
*/
initSwell()
const shopProducts = await getProducts('posters')
const shopProductsRes: any = await fetch(`${SWELL_API_ENDPOINT}/products`, {
headers: {
Authorization: `Basic ${Buffer.from(`${PUBLIC_SWELL_STORE_ID}:${SWELL_API_TOKEN}`).toString('base64')}`
},
})
const shopProducts = await shopProductsRes.json()
if (shopProducts) {
return {