feature (#2): add joke api endpoint
This commit is contained in:
15
netlify/functions/joke.js
Normal file
15
netlify/functions/joke.js
Normal file
@ -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),
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user