Use Swell REST API for fetching products
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user