Skip to content

Commit

Permalink
update ts files for netlify env key
Browse files Browse the repository at this point in the history
  • Loading branch information
marjoriekohn committed Sep 17, 2023
1 parent 558377c commit 536c315
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 16 deletions.
1 change: 1 addition & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[[redirects]]
debug = true
from = "/api/*"
to = "https://api.api-ninjas.com/v1/:splat"
status = 200
Expand Down
1 change: 0 additions & 1 deletion src/dist/fetchQuotes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/dist/fetchQuotes.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/dist/showQuote.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 2 additions & 11 deletions src/ts/fetchQuotes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { handleError } from "./handleError";
import { showQuote } from "./showQuote";

// TODO: store the API key in a .env file
const apiUrl = "https://api.api-ninjas.com/v1/quotes?category=";
const apiKey = "API_KEY";

/**
* Fetches a random quote based on the user's chosen category.
* @param userCategory - The category chosen by the user.
Expand All @@ -14,17 +10,12 @@ export async function fetchQuotes(userCategory: string): Promise<void> {
let randomQuote = { quote: '', author: '' };

try {
const quotesResponse = await fetch(apiUrl + userCategory, {
headers: {
'X-Api-Key': apiKey,
},
});

const quotesResponse = await fetch('/api/quotes?category=' + userCategory);
const quotesData = await quotesResponse.json();
const randomIndex = Math.floor(Math.random() * quotesData.length);
randomQuote = quotesData[randomIndex];
showQuote(randomQuote);
} catch (err) {
handleError(err);
}
}
}
2 changes: 0 additions & 2 deletions src/ts/showQuote.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// import Typed from "typed.js";

import Typed from "../../node_modules/typed.js/index";

/**
Expand Down

0 comments on commit 536c315

Please sign in to comment.