-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplifying jokes service because icanhazdadjoke supports content neg…
…otiation - requesting text/plain instead of html
- Loading branch information
Amir Ziaei
committed
Apr 9, 2024
1 parent
cdb092a
commit 84a98b1
Showing
3 changed files
with
4 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import * as cheerio from 'cheerio' | ||
|
||
export async function getRandomDadJoke() { | ||
const response = await fetch('https://icanhazdadjoke.com/') | ||
const html = await response.text() | ||
const $ = cheerio.load(html) | ||
return $('.card-content p.subtitle').text().trim() | ||
const response = await fetch('https://icanhazdadjoke.com/', { | ||
headers: { Accept: 'text/plain' }, | ||
}) | ||
return (await response.text()).trim() | ||
} |