Added Scraper API option. #100

Merged
RabbIT09-n merged 3 commits from scraper-api-support into master 2020-02-25 16:10:44 +01:00
3 changed files with 20 additions and 3 deletions

View File

@@ -45,6 +45,9 @@ const USER_AGENT =
process.env.USER_AGENT ||
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36";
const USE_SCRAPER_API = process.env.USE_SCRAPER_API || 1; //Default to use
const SCRAPER_API_KEY = process.env.SCRAPER_API_KEY || "";
module.exports = {
APP_PORT,
APP_URL,
@@ -59,5 +62,7 @@ module.exports = {
STAGING,
CHECK_UP_DAYS,
PROSTOR_LOGIN,
USER_AGENT
USER_AGENT,
USE_SCRAPER_API,
SCRAPER_API_KEY
};

View File

@@ -1,5 +1,9 @@
const nodeFetch = require("node-fetch");
const { USER_AGENT } = require("../config/appConfig");
const {
USER_AGENT,
USE_SCRAPER_API,
SCRAPER_API_KEY
} = require("../config/appConfig");
const fetch = async (url, options = {}) => {
const newOptions = Object.assign({}, options);
@@ -7,7 +11,11 @@ const fetch = async (url, options = {}) => {
newOptions["headers"] = {};
}
newOptions["headers"]["User-Agent"] = USER_AGENT;
return nodeFetch(url, newOptions);
const urlAdaptedForScraping = USE_SCRAPER_API
? `http://api.scraperapi.com/?api_key=${SCRAPER_API_KEY}&url=${url}`
: url;
return nodeFetch(urlAdaptedForScraping, newOptions);
};
module.exports = fetch;

View File

@@ -22,6 +22,10 @@ GA_ID=Google Analytics ID
#=============== GOOGLE MAPS =============#
API_MAP_KEY=(your-key-here)
#=============== SCRAPER API SUPORT =============#
USE_SCRAPER_API= To turn it on (1) or off (0)
SCRAPER_API_KEY= Key for Scraper api
#=============== AWS SDK EMAIL SETTINGS =======#
AWS_KEY_ID=(your-key-here)
AWS_SECRET_ACCESS_KEY=(your-key-here)