Skip to content
This repository was archived by the owner on May 17, 2019. It is now read-only.

Commit 5f6b943

Browse files
author
Michael Wenzel
committed
hardcode crossorigin script attribute
1 parent ae778bd commit 5f6b943

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

plugins/ssr-plugin.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ const SSRBodyTemplate = createPlugin/*:: <SSRBodyTemplateDepsType,SSRBodyTemplat
113113
let preloadHints = [];
114114

115115
for (let url of criticalChunkUrls) {
116-
const crossoriginAttr = url.startsWith(__webpack_public_path__)
117-
? ''
118-
: ' crossorigin="anonymous"';
116+
const crossoriginAttr = process.env.CDN_URL
117+
? ' crossorigin="anonymous"'
118+
: '';
119119
preloadHints.push(
120120
`<link rel="preload" href="${url}" nonce="${
121121
ctx.nonce

test/e2e/dynamic-import-app/test.js

+37
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,43 @@ test('`fusion build` app with dynamic imports integration', async () => {
215215
proxy.close();
216216
}, 100000);
217217

218+
test('`fusion build` app with CDN_URL and same-origin', async () => {
219+
await cmd(`build --dir=${dir} --production`);
220+
221+
// Run puppeteer test to ensure that page loads with dynamic content.
222+
const {proc, port} = await start(`--dir=${dir}`, {
223+
env: Object.assign({}, process.env, {
224+
CDN_URL: 'https://cdn.com',
225+
NODE_ENV: 'production',
226+
}),
227+
});
228+
229+
const browser = await puppeteer.launch({
230+
args: ['--no-sandbox', '--disable-setuid-sandbox'],
231+
});
232+
const page = await browser.newPage();
233+
await page.setRequestInterception(true);
234+
await page.on('request', request => {
235+
// Ignore CDN requests since they will cause the browser to hang.
236+
if (request.url().startsWith('https://cdn.com')) {
237+
request.abort();
238+
} else {
239+
request.continue();
240+
}
241+
});
242+
await page.goto(`http://localhost:${port}/`, {waitUntil: 'load'});
243+
244+
t.ok(
245+
await page.$$eval('script[src]:not([type="application/json"])', els =>
246+
els.every(el => el.crossOrigin === 'anonymous')
247+
),
248+
'non-module scripts have crossorigin attribute'
249+
);
250+
251+
browser.close();
252+
proc.kill();
253+
}, 100000);
254+
218255
test('`fusion build` app with Safari user agent and same-origin', async () => {
219256
var env = Object.create(process.env);
220257
env.NODE_ENV = 'production';

0 commit comments

Comments
 (0)