Skip to content

Commit

Permalink
fix(fetch): reenable scraper proxy api
Browse files Browse the repository at this point in the history
  • Loading branch information
tfkhdyt committed Oct 10, 2023
1 parent 38552b5 commit 2f76a62
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const {
DATABASE_AUTH_TOKEN,
MIDTRANS_SERVER_KEY,
MIDTRANS_CLIENT_KEY,
SCRAPER_API_KEY,
} = parseEnv(process.env, {
BOT_DOMAIN: z.string().url().optional(),
PORT: port().default(3000),
Expand All @@ -20,6 +21,7 @@ export const {
DATABASE_AUTH_TOKEN: z.string().optional(),
MIDTRANS_SERVER_KEY: z.string().min(1),
MIDTRANS_CLIENT_KEY: z.string().min(1),
SCRAPER_API_KEY: z.string().min(1),
})

export const message = {
Expand Down
14 changes: 7 additions & 7 deletions src/services/scraper.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { CheerioAPI, load } from 'cheerio'

import { SCRAPER_API_KEY } from '../config/config.js'
import { Pengertian } from '../types/scraper.js'

const fetchHTML = async (keyword: string) => {
try {
// const response = await fetch(
// `http://api.scraperapi.com?api_key=${config.scraperAPIKey
// }&url=https://kbbi.kemdikbud.go.id/entri/${this.keyword
// .toLowerCase()
// .trim()}`,
// )
const response = await fetch(
`https://kbbi.kemdikbud.go.id/entri/${keyword.toLowerCase().trim()}`,
`http://api.scraperapi.com?api_key=${SCRAPER_API_KEY}&url=https://kbbi.kemdikbud.go.id/entri/${keyword
.toLowerCase()
.trim()}`,
)
// const response = await fetch(
// `https://kbbi.kemdikbud.go.id/entri/${keyword.toLowerCase().trim()}`,
// )
const data = await response.text()
if (!response.ok) {
throw new Error('Gagal untuk mengakses halaman KBBI')
Expand Down

0 comments on commit 2f76a62

Please sign in to comment.