Skip to content

Commit

Permalink
fix quote fetcher to add fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
ethancedwards8 committed Dec 29, 2024
1 parent a4d636e commit bd39d66
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,18 @@ export async function getServerSideProps() {
// local development
// const res = { quote: "Quote", author: "Author" };
// const quotes = res;

// production
const res = await fetch(`https://api.ethancedwards.com/quotes/v1`);
const quotes = await res.json();

let quotes;
let final;

const posts = getAllPosts();

await fetch(`https://api.ethancedwards.com/quotes/v1`).then((res) => {
final = res;
}).catch((error) => {
quotes = { quote: "Value your freedom or you will lose it, teaches history", author: "Richard Stallman" };
});
quotes = await final.json();

return { props: { quotes, posts } };
}

0 comments on commit bd39d66

Please sign in to comment.