Skip to content

Commit

Permalink
simplifying jokes service because icanhazdadjoke supports content neg…
Browse files Browse the repository at this point in the history
…otiation - requesting text/plain instead of html
  • Loading branch information
Amir Ziaei committed Apr 9, 2024
1 parent cdb092a commit 84a98b1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
1 change: 0 additions & 1 deletion apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
},
"dependencies": {
"@playwright/test": "^1.43.0",
"cheerio": "^1.0.0-rc.12",
"cross-env": "^7.0.3",
"dotenv": "^16.4.5",
"zod": "^3.22.4"
Expand Down
10 changes: 4 additions & 6 deletions apps/app/src/services/jokes.ts
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()
}
Binary file modified bun.lockb
Binary file not shown.

0 comments on commit 84a98b1

Please sign in to comment.