Skip to content

Commit

Permalink
fix(override-base-url): use overrideBaseURL from site.getConfig().get…
Browse files Browse the repository at this point in the history
…FetchConfig()
  • Loading branch information
iuliag committed Feb 28, 2025
1 parent 2eb349e commit 0e04c23
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ class Site extends BaseModel {
* @throws {Error} if the final URL cannot be resolved.
*/
async resolveFinalURL() {
const overrideBaseURL = this.getConfig()?.fetchConfig?.overrideBaseURL;
const overrideBaseURL = this.getConfig()?.getFetchConfig()?.overrideBaseURL;
if (isValidUrl(overrideBaseURL)) {
return overrideBaseURL.replace(/^https?:\/\//, '');
}

const userAgentConfigured = this.getConfig()
?.fetchConfig?.headers?.['User-Agent'];
const userAgentConfigured = this.getConfig()?.getFetchConfig()?.headers?.['User-Agent'];
if (hasText(userAgentConfigured)) {
return composeAuditURL(this.getBaseURL(), userAgentConfigured);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe('SiteModel', () => {
it('resolves the final URL using the base URL', async () => {
instance.setBaseURL('https://spacecat.com');
const config = instance.getConfig();
config.fetchConfig = {};
config.getFetchConfig = () => ({});

nock(instance.getBaseURL())
.get('/')
Expand All @@ -188,7 +188,7 @@ describe('SiteModel', () => {

it('resolves the final URL using the overrideBaseURL', async () => {
const config = instance.getConfig();
config.fetchConfig = { overrideBaseURL: 'http://override.com' };
config.getFetchConfig = () => ({ overrideBaseURL: 'http://override.com' });

const finalURL = await instance.resolveFinalURL();

Expand All @@ -199,7 +199,7 @@ describe('SiteModel', () => {
instance.setBaseURL('https://spacecat.com');
const userAgent = 'Mozilla/5.0';
const config = instance.getConfig();
config.fetchConfig = { headers: { 'User-Agent': userAgent } };
config.getFetchConfig = () => ({ headers: { 'User-Agent': userAgent } });

nock(instance.getBaseURL(), {
reqheaders: {
Expand Down

0 comments on commit 0e04c23

Please sign in to comment.