Move scraper api base url to the ENV; send URL as base64 string
This commit is contained in:
@@ -2,7 +2,8 @@ const nodeFetch = require("node-fetch");
|
||||
const {
|
||||
USER_AGENT,
|
||||
USE_SCRAPER_API,
|
||||
SCRAPER_API_KEY
|
||||
SCRAPER_API_KEY,
|
||||
SCRAPER_API_BASE_URL
|
||||
} = require("../config/appConfig");
|
||||
|
||||
const fetch = async (url, options = {}) => {
|
||||
@@ -11,8 +12,9 @@ const fetch = async (url, options = {}) => {
|
||||
newOptions["headers"] = {};
|
||||
}
|
||||
newOptions["headers"]["User-Agent"] = USER_AGENT;
|
||||
|
||||
const urlAdaptedForScraping = USE_SCRAPER_API
|
||||
? `http://api.scraperapi.com/?api_key=${SCRAPER_API_KEY}&url=${url}`
|
||||
? `${SCRAPER_API_BASE_URL}?api_key=${SCRAPER_API_KEY}&url=${Buffer.from(url).toString('base64')}`
|
||||
: url;
|
||||
|
||||
return nodeFetch(urlAdaptedForScraping, newOptions);
|
||||
|
||||
Reference in New Issue
Block a user