import { getSecret } from 'wix-secrets-backend';
import { fetch } from 'wix-fetch';
export const getApiKey = async () => {
try {
const privateKey = await getSecret("marvelKey");
console.log(privateKey); // For debugging purposes, remove this in production
} catch (error) {
console.error("Error getting API key:", error);
}
};
export const getCharacters = async () => {
try {
const ts = "1";
const publicKey = "9758c412227abfdf55083adedbf74b1a";
const privateKey = await getSecret("marvelKey");
// Use wixCrypto for secure hashing (replace md5 with a secure algorithm)
const hash = await wixCrypto.sha256(ts + privateKey + publicKey);
const url = `https://gateway.marvel.com/v1/public/characters?ts=${ts}&apikey=${publicKey}&hash=${hash}`;
const response = await fetch(url);
if (!response.ok) {
throw new Error("Error fetching characters:", await response.text());
}
const characterList = await response.json();
console.log(characterList);
} catch (error) {
console.error("Error fetching characters:", error);
}
};
top of page
No plans availableOnce there are plans available for purchase, you’ll see them here. bottom of page