UNPKG

chimi-scraper

Version:

A TypeScript library for scraping game data from itch.io with a clean, scalable architecture

53 lines 2.03 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HttpClient = void 0; const axios_1 = __importDefault(require("axios")); class HttpClient { constructor(baseURL, timeout = 10000) { this.baseURL = baseURL; this.timeout = timeout; } async get(url, config) { try { const response = await axios_1.default.get(url, { baseURL: this.baseURL, timeout: this.timeout, headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Language': 'en-US,en;q=0.5', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'keep-alive', 'Upgrade-Insecure-Requests': '1', }, ...config, }); return response.data; } catch (error) { throw new Error(`HTTP request failed: ${error}`); } } async post(url, data, config) { try { const response = await axios_1.default.post(url, data, { baseURL: this.baseURL, timeout: this.timeout, headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', 'Content-Type': 'application/json', }, ...config, }); return response.data; } catch (error) { throw new Error(`HTTP request failed: ${error}`); } } } exports.HttpClient = HttpClient; //# sourceMappingURL=http.js.map