Skip to content

Commit

Permalink
fix: adapt base url to netlify (#784)
Browse files Browse the repository at this point in the history
* fix: adapt base url to netlify

* fix: tests

* fix: netlify constants

* chore: remove comment
  • Loading branch information
milljoniaer authored Nov 28, 2023
1 parent 31d652a commit ed71f56
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 62 deletions.
9 changes: 5 additions & 4 deletions gatsby/config-options/constants.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { buildGatsbyCloudPreviewUrl } from '../util/build-gatsby-cloud-preview-url';
import { buildNetlifyPreviewUrl } from '../util/build-netlify-preview-url';
export const RSS_FEED_URL = '/blog/rss.xml';
export const DEFAULT_META_IMAGE_URL_PATH = '/sy-share-image.jpg';
export const GATSBY_SITE_PREFIX = process.env.GATSBY_SITE_PREFIX || '';
export const BRANCH_PREVIEW_URL = buildGatsbyCloudPreviewUrl({
prefix: GATSBY_SITE_PREFIX,
export const NETLIFY_DOMAIN_NAME = process.env.GATSBY_NETLIFY_DOMAIN_NAME || '';
export const BRANCH_PREVIEW_URL = buildNetlifyPreviewUrl({
domainName: NETLIFY_DOMAIN_NAME,
branch: process.env.BRANCH,
reviewId: process.env.REVIEW_ID,
});

// either use a branch preview url if any
Expand Down
35 changes: 0 additions & 35 deletions gatsby/util/build-gatsby-cloud-preview-url.test.ts

This file was deleted.

23 changes: 0 additions & 23 deletions gatsby/util/build-gatsby-cloud-preview-url.ts

This file was deleted.

30 changes: 30 additions & 0 deletions gatsby/util/build-netlify-preview-url.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { buildNetlifyPreviewUrl } from './build-netlify-preview-url';

describe('build-netlify-preview-url', () => {
test('should return a valid url', () => {
const url = buildNetlifyPreviewUrl({
domainName: 'satellytes',
branch: 'feature-branch-1',
reviewId: '123',
});
expect(url).toBe('https://deploy-preview-123--satellytes.netlify.app/');
});

test('should return null for the production branch', () => {
const url = buildNetlifyPreviewUrl({
domainName: 'satellytescommain',
branch: 'main',
reviewId: '123',
});
expect(url).toBe(null);
});

test('should return null if no domainName is given', () => {
const url = buildNetlifyPreviewUrl({
domainName: null,
branch: 'something',
reviewId: '123',
});
expect(url).toBe(null);
});
});
8 changes: 8 additions & 0 deletions gatsby/util/build-netlify-preview-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const PRODUCTION_BRANCH = 'main';
export const buildNetlifyPreviewUrl = ({ domainName, reviewId, branch }) => {
if (!domainName || !reviewId || branch === PRODUCTION_BRANCH) {
return null;
}

return `https://deploy-preview-${reviewId}--${domainName}.netlify.app/`;
};

0 comments on commit ed71f56

Please sign in to comment.