add env logging
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
import Medusa from "@medusajs/js-sdk"
|
||||
import Medusa from "@medusajs/js-sdk";
|
||||
|
||||
// Defaults to standard port for Medusa server
|
||||
let MEDUSA_BACKEND_URL = "http://localhost:9000"
|
||||
let MEDUSA_BACKEND_URL = "http://localhost:9000";
|
||||
|
||||
if (process.env.MEDUSA_BACKEND_URL) {
|
||||
MEDUSA_BACKEND_URL = process.env.MEDUSA_BACKEND_URL
|
||||
MEDUSA_BACKEND_URL = process.env.MEDUSA_BACKEND_URL;
|
||||
}
|
||||
|
||||
export const sdk = new Medusa({
|
||||
export const SDK_CONFIG = {
|
||||
baseUrl: MEDUSA_BACKEND_URL,
|
||||
debug: process.env.NODE_ENV === "development",
|
||||
publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
|
||||
})
|
||||
};
|
||||
|
||||
export const sdk = new Medusa(SDK_CONFIG);
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
"use server"
|
||||
"use server";
|
||||
|
||||
import { sdk } from "@lib/config"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { getCacheOptions } from "./cookies"
|
||||
import { sdk, SDK_CONFIG } from "@lib/config";
|
||||
import { HttpTypes } from "@medusajs/types";
|
||||
import { getCacheOptions } from "./cookies";
|
||||
|
||||
export const retrieveCollection = async (id: string) => {
|
||||
const next = {
|
||||
...(await getCacheOptions("collections")),
|
||||
}
|
||||
};
|
||||
|
||||
return sdk.client
|
||||
.fetch<{ collection: HttpTypes.StoreCollection }>(
|
||||
@@ -17,19 +17,19 @@ export const retrieveCollection = async (id: string) => {
|
||||
cache: "force-cache",
|
||||
}
|
||||
)
|
||||
.then(({ collection }) => collection)
|
||||
}
|
||||
.then(({ collection }) => collection);
|
||||
};
|
||||
|
||||
export const listCollections = async (
|
||||
queryParams: Record<string, string> = {}
|
||||
): Promise<{ collections: HttpTypes.StoreCollection[]; count: number }> => {
|
||||
const next = {
|
||||
...(await getCacheOptions("collections")),
|
||||
}
|
||||
|
||||
queryParams.limit = queryParams.limit || "100"
|
||||
queryParams.offset = queryParams.offset || "0"
|
||||
};
|
||||
|
||||
queryParams.limit = queryParams.limit || "100";
|
||||
queryParams.offset = queryParams.offset || "0";
|
||||
console.log("SDK_CONFIG: ", SDK_CONFIG.baseUrl);
|
||||
return sdk.client
|
||||
.fetch<{ collections: HttpTypes.StoreCollection[]; count: number }>(
|
||||
"/store/collections",
|
||||
@@ -39,15 +39,15 @@ export const listCollections = async (
|
||||
cache: "force-cache",
|
||||
}
|
||||
)
|
||||
.then(({ collections }) => ({ collections, count: collections.length }))
|
||||
}
|
||||
.then(({ collections }) => ({ collections, count: collections.length }));
|
||||
};
|
||||
|
||||
export const getCollectionByHandle = async (
|
||||
handle: string
|
||||
): Promise<HttpTypes.StoreCollection> => {
|
||||
const next = {
|
||||
...(await getCacheOptions("collections")),
|
||||
}
|
||||
};
|
||||
|
||||
return sdk.client
|
||||
.fetch<HttpTypes.StoreCollectionListResponse>(`/store/collections`, {
|
||||
@@ -55,5 +55,5 @@ export const getCollectionByHandle = async (
|
||||
next,
|
||||
cache: "force-cache",
|
||||
})
|
||||
.then(({ collections }) => collections[0])
|
||||
}
|
||||
.then(({ collections }) => collections[0]);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user