Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
Bugfix: properly handle situation where APIFY_API_BASE_URL env var is missing, added unit test for that, bumped package.json version
Jan Curn631a8f262180
diff --git a/package.json b/package.jsonindex 3630a9477..980ce439e 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "apifier",- "version": "0.0.46",+ "version": "0.0.47","description": "Apifier runtime for JavaScript","main": "build/index.js","keywords": [diff --git a/src/utils.js b/src/utils.jsindex 8d84ba180..8d38c10a0 100644--- a/src/utils.js+++ b/src/utils.js@@ -68,11 +68,15 @@ export const nodeifyPromise = (promise, callback) => {*/export const newClient = () => {const opts = {- baseUrl: process.env[APIFY_ENV_VARS.API_BASE_URL] || null,userId: process.env[APIFY_ENV_VARS.USER_ID] || null,token: process.env[APIFY_ENV_VARS.TOKEN] || null,};+ // Only set baseUrl if overridden by env var, so that 'https://api.apifier.com' is used by default.+ // This simplifies local development, which should run against production unless user wants otherwise.+ const apiBaseUrl = process.env[APIFY_ENV_VARS.API_BASE_URL];+ if (apiBaseUrl) opts.baseUrl = apiBaseUrl;+return new ApifyClient(opts);};diff --git a/test/utils.js b/test/utils.jsindex 0268e01e5..035072453 100644--- a/test/utils.js+++ b/test/utils.js@@ -50,6 +50,19 @@ describe('utils.newClient()', () => {expect(opts.token).to.eql('token');expect(opts.baseUrl).to.eql('http://www.example.com:1234/path/');});++ it('uses correct default if APIFY_API_BASE_URL is not defined', () => {+ delete process.env.APIFY_API_BASE_URL;+ process.env.APIFY_USER_ID = 'userId';+ process.env.APIFY_TOKEN = 'token';+ const client = utils.newClient();++ const opts = client.getOptions();++ expect(opts.userId).to.eql('userId');+ expect(opts.token).to.eql('token');+ expect(opts.baseUrl).to.eql('https://api.apifier.com');+ });});