1
0
Fork 0
forked from OpenNeo/impress
impress/src/server/neopets.js
Matt Dunn-Rankin 90ad9feb0c move neopets.com loading into server
the client stuff worked locally, but not in prod because you can't request http from https, even with cors set up correctly 😅
2020-04-25 06:50:34 -07:00

20 lines
456 B
JavaScript

const fetch = require("node-fetch");
async function loadPetData(petName) {
const res = await fetch(
`http://www.neopets.com/amfphp/json.php/CustomPetService.getViewerData` +
`/${petName}`
);
if (!res.ok) {
throw new Error(`neopets.com returned: ${res.statusText}`);
}
const json = await res.json();
if (!json.custom_pet) {
throw new Error(`missing custom_pet data`);
}
return json;
}
module.exports = { loadPetData };