From 1af5c0702a35a2dcf1b3d64ff2f1d742d3d7f9f5 Mon Sep 17 00:00:00 2001 From: Ben Hong Date: Wed, 23 Feb 2022 08:23:47 -0800 Subject: [PATCH 1/2] fix (#2): add async keyword --- netlify/functions/joke.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netlify/functions/joke.js b/netlify/functions/joke.js index 5ef6d1b..a07759a 100644 --- a/netlify/functions/joke.js +++ b/netlify/functions/joke.js @@ -1,7 +1,7 @@ // Jokes provided from the lovely folks at https://icanhazdadjoke.com import jokes from './jokes.json' -export const handler = (event) => { +export const handler = async () => { // Generates a random index based on the length of the jokes array const randomIndex = Math.floor(Math.random() * jokes.length) const randomJoke = jokes[randomIndex] From 5534179990a6dfd2ffa2c959f7637788752cf3f3 Mon Sep 17 00:00:00 2001 From: Ben Hong Date: Wed, 23 Feb 2022 08:25:34 -0800 Subject: [PATCH 2/2] refactor (#2): separate static files from functions --- netlify/functions/{ => data}/jokes.json | 0 netlify/functions/joke.js | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename netlify/functions/{ => data}/jokes.json (100%) diff --git a/netlify/functions/jokes.json b/netlify/functions/data/jokes.json similarity index 100% rename from netlify/functions/jokes.json rename to netlify/functions/data/jokes.json diff --git a/netlify/functions/joke.js b/netlify/functions/joke.js index a07759a..826e21b 100644 --- a/netlify/functions/joke.js +++ b/netlify/functions/joke.js @@ -1,5 +1,5 @@ // Jokes provided from the lovely folks at https://icanhazdadjoke.com -import jokes from './jokes.json' +import jokes from './data/jokes.json' export const handler = async () => { // Generates a random index based on the length of the jokes array