diff --git a/static/index.html b/public/index.html
similarity index 97%
rename from static/index.html
rename to public/index.html
index 4b4abf2..5b3c7da 100644
--- a/static/index.html
+++ b/public/index.html
@@ -3,8 +3,8 @@
-
-
+
+
Clever name
@@ -53,7 +53,6 @@
-
diff --git a/server.js b/server.js
index e766eb6..6864eb7 100644
--- a/server.js
+++ b/server.js
@@ -12,10 +12,12 @@ const PORT = process.env.PORT || 3000;
// Serve static files from the "static" directory
app.use(bodyParser.urlencoded({extended: true }));
app.use(express.static("static"));
+app.use(express.static("public"));
// Route to handle search submission
app.get("/search", async (req, res) => {
const searchTerm = req.query.searchTerm;
+ console.log(`searchTerm: ${searchTerm}`)
try {
// Make a request to the JokeAPI with the search term
diff --git a/static/js/script.js b/static/js/script.js
index 8924c62..6f78d25 100644
--- a/static/js/script.js
+++ b/static/js/script.js
@@ -5,20 +5,23 @@ document.addEventListener("DOMContentLoaded", () => {
// Function to handle form submission
const handleFormSubmit = async (event) => {
+ console.log("Submit happened")
event.preventDefault(); // Prevent the default form submission behavior
const searchTerm = searchInput.value; // Get the search term from the input field
try {
+ // Make a GET request to the server with search term in route
const response = await fetch(`/search?searchTerm=${encodeURIComponent(searchTerm)}`, {
method: "GET"
});
-
+ console.log(`response: ${response}`)
+ // Check if response is successful
if (!response.ok) {
throw new Error("Failed to fetch joke");
}
-
+ // Parse the JSON response to get joke data
const data = await response.json();
-
+ // Deal with different joke structures
if (data.type === "single") {
jokeElement.textContent = data.joke;
} else if (data.type === "twopart") {
@@ -27,8 +30,9 @@ document.addEventListener("DOMContentLoaded", () => {
throw new Error("Unknown joke format");
}
} catch (error) {
+ // Catch errors that might occur during fetch or parsing
console.error("Error fetching joke:", error);
- jokeElement.textContent = "Failed to fetch joke";
+ jokeElement.textContent = "Sorry, we couldn't find a relevant joke!";
}
};
diff --git a/static/scripts/script.js b/static/scripts/script.js
deleted file mode 100644
index e69de29..0000000