Create reusable Swell fetch functions
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
import { error } from '@sveltejs/kit'
|
||||
import type { PageServerLoad } from './$types'
|
||||
import base64 from 'base-64'
|
||||
import { fetchAPI } from '$utils/api'
|
||||
import { PUBLIC_SWELL_STORE_ID } from '$env/static/public'
|
||||
import { SWELL_API_TOKEN, SWELL_API_ENDPOINT } from '$env/static/private'
|
||||
import { fetchSwell } from '$utils/functions/shopServer'
|
||||
|
||||
export const load: PageServerLoad = async () => {
|
||||
try {
|
||||
@@ -57,12 +55,7 @@ export const load: PageServerLoad = async () => {
|
||||
/**
|
||||
* Get products data from Swell
|
||||
*/
|
||||
const shopProductsRes: any = await fetch(`${SWELL_API_ENDPOINT}/products`, {
|
||||
headers: {
|
||||
Authorization: `Basic ${base64.encode(`${PUBLIC_SWELL_STORE_ID}:${SWELL_API_TOKEN}`)}`
|
||||
},
|
||||
})
|
||||
const shopProducts = await shopProductsRes.json()
|
||||
const shopProducts: any = await fetchSwell('/products')
|
||||
|
||||
if (shopProducts) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user