Skip to content

Commit 1359feb

Browse files
committed
Use CORS if not in stories only
1 parent 7f6e13f commit 1359feb

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

dotcom-rendering/src/components/SelfHostedVideo.importable.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ type Props = {
140140
fallbackImageAlt: CardPictureProps['alt'];
141141
fallbackImageAspectRatio: CardPictureProps['aspectRatio'];
142142
linkTo: string;
143+
/**
144+
* If CORS are enabled, the video request will include CORS headers.
145+
*/
146+
enableCors?: boolean;
143147
subtitleSource?: string;
144148
subtitleSize: SubtitleSize;
145149
};
@@ -158,6 +162,7 @@ export const SelfHostedVideo = ({
158162
fallbackImageAlt,
159163
fallbackImageAspectRatio,
160164
linkTo,
165+
enableCors = true,
161166
subtitleSource,
162167
subtitleSize,
163168
}: Props) => {
@@ -706,6 +711,7 @@ export const SelfHostedVideo = ({
706711
AudioIcon={hasAudio ? AudioIcon : null}
707712
preloadPartialData={preloadPartialData}
708713
showPlayIcon={showPlayIcon}
714+
enableCors={enableCors}
709715
subtitleSource={subtitleSource}
710716
subtitleSize={subtitleSize}
711717
activeCue={activeCue}

dotcom-rendering/src/components/SelfHostedVideo.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const Loop5to4: Story = {
3232
uniqueId: 'test-video-1',
3333
atomId: 'test-atom-1',
3434
videoStyle: 'Loop',
35+
enableCors: false,
3536
height: 720,
3637
width: 900,
3738
posterImage:

dotcom-rendering/src/components/SelfHostedVideoPlayer.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ type Props = {
122122
posterImage?: string;
123123
preloadPartialData: boolean;
124124
showPlayIcon: boolean;
125+
enableCors?: boolean;
125126
subtitleSource?: string;
126127
subtitleSize?: SubtitleSize;
127128
/* used in custom subtitle overlays */
@@ -162,6 +163,7 @@ export const SelfHostedVideoPlayer = forwardRef(
162163
AudioIcon,
163164
preloadPartialData,
164165
showPlayIcon,
166+
enableCors = true,
165167
subtitleSource,
166168
subtitleSize,
167169
activeCue,
@@ -183,16 +185,6 @@ export const SelfHostedVideoPlayer = forwardRef(
183185
showPlayIcon ? 'play' : 'pause'
184186
}-${atomId}`;
185187

186-
/**
187-
* To show subtitles, CORS must be enabled as it allows access to the VTT file.
188-
*
189-
* CORS should be enabled in production so that requests are consistent with respect to CORS.
190-
* If a client requests a video without CORS, then later made a request to the same video with
191-
* CORS, then this request could fail as the response could be cached without the headers.
192-
*/
193-
const requestCORS =
194-
showSubtitles || process.env.NODE_ENV === 'production';
195-
196188
return (
197189
<>
198190
{/* eslint-disable-next-line jsx-a11y/media-has-caption -- Not all videos require captions. */}
@@ -202,7 +194,7 @@ export const SelfHostedVideoPlayer = forwardRef(
202194
videoStyles(width, height),
203195
showSubtitles && subtitleStyles(subtitleSize),
204196
]}
205-
crossOrigin={requestCORS ? 'anonymous' : undefined}
197+
crossOrigin={enableCors ? 'anonymous' : undefined}
206198
ref={ref}
207199
tabIndex={0}
208200
data-testid="self-hosted-video-player"

0 commit comments

Comments
 (0)