From 06bd1e1dff49b462e5eb339ce3f43598a2a493a4 Mon Sep 17 00:00:00 2001 From: Ben Hong Date: Tue, 22 Feb 2022 17:13:34 -0800 Subject: [PATCH 1/6] config (#2): add esbuild configuration for serverless functions --- netlify.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/netlify.toml b/netlify.toml index 75e97ee..781367b 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,4 +1,4 @@ -## This is the configuration file for Netlify +## This is the configuration file for Netlify ## https://docs.netlify.com/configure-builds/file-based-configuration/ [build] @@ -15,3 +15,6 @@ to = "/.netlify/functions/:splat" # all function calls will go to this path status = 200 # ok code force = true # ensure to always redirect + +[functions] + node_bundler = "esbuild" From 07b98614155021a85946bd13955098f4cd5c68f5 Mon Sep 17 00:00:00 2001 From: Ben Hong Date: Tue, 22 Feb 2022 17:14:07 -0800 Subject: [PATCH 2/6] feature (#2): add joke api endpoint --- netlify/functions/joke.js | 15 +++++++++++++++ netlify/functions/jokes.json | 7 +++++++ 2 files changed, 22 insertions(+) create mode 100644 netlify/functions/joke.js create mode 100644 netlify/functions/jokes.json diff --git a/netlify/functions/joke.js b/netlify/functions/joke.js new file mode 100644 index 0000000..5ef6d1b --- /dev/null +++ b/netlify/functions/joke.js @@ -0,0 +1,15 @@ +// Jokes provided from the lovely folks at https://icanhazdadjoke.com +import jokes from './jokes.json' + +export const handler = (event) => { + // Generates a random index based on the length of the jokes array + const randomIndex = Math.floor(Math.random() * jokes.length) + const randomJoke = jokes[randomIndex] + + // Netlify Functions need to return an object with a statusCode + // Other properties such as headers or body can also be included. + return { + statusCode: 200, + body: JSON.stringify(randomJoke), + } +} diff --git a/netlify/functions/jokes.json b/netlify/functions/jokes.json new file mode 100644 index 0000000..52f6a7f --- /dev/null +++ b/netlify/functions/jokes.json @@ -0,0 +1,7 @@ +[ + "My New Years resolution is to stop leaving things so late.", + "Child: Dad, make me a sandwich. Dad: Poof! You're a sandwich.", + "The invention of the wheel was what got things rolling", + "What kind of music do mummy's like? Rap", + "What do you get when you cross a chicken with a skunk? A fowl smell!" +] From 3ed9a2d57d7a47cfc81c5ae9f06db08bcbf960e9 Mon Sep 17 00:00:00 2001 From: Ben Hong Date: Tue, 22 Feb 2022 17:22:13 -0800 Subject: [PATCH 3/6] feature (#2): add joke block component to home page --- components/JokeBlock.vue | 25 +++++++++++++++++++++++++ pages/index.vue | 6 +++++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 components/JokeBlock.vue diff --git a/components/JokeBlock.vue b/components/JokeBlock.vue new file mode 100644 index 0000000..73ea89e --- /dev/null +++ b/components/JokeBlock.vue @@ -0,0 +1,25 @@ + + + + + diff --git a/pages/index.vue b/pages/index.vue index c3dd9b5..140ec6f 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1,6 +1,10 @@ +