Skip to content

Commit dcec597

Browse files
committed
fix(@angular-devkit/build-angular): properly configure headers for media resources and HTML page
Headers were not configured correctly. Closes #27464
1 parent c5f20a3 commit dcec597

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import { executeDevServer } from '../../index';
10+
import { executeOnceAndFetch } from '../execute-fetch';
11+
import { describeServeBuilder } from '../jasmine-helpers';
12+
import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO } from '../setup';
13+
14+
describeServeBuilder(
15+
executeDevServer,
16+
DEV_SERVER_BUILDER_INFO,
17+
(harness, setupTarget, isViteRun) => {
18+
(isViteRun ? describe : xdescribe)('option: "headers"', () => {
19+
beforeEach(async () => {
20+
setupTarget(harness, {
21+
styles: ['src/styles.css'],
22+
});
23+
24+
// Application code is not needed for these tests
25+
await harness.writeFile('src/main.ts', '');
26+
await harness.writeFile('src/styles.css', '');
27+
});
28+
29+
it('index response headers should include configured header', async () => {
30+
harness.useTarget('serve', {
31+
...BASE_OPTIONS,
32+
headers: {
33+
'x-custom': 'foo',
34+
},
35+
});
36+
37+
const { result, response } = await executeOnceAndFetch(harness, '/');
38+
39+
expect(result?.success).toBeTrue();
40+
expect(await response?.headers.get('x-custom')).toBe('foo');
41+
});
42+
43+
it('media resource response headers should include configured header', async () => {
44+
await harness.writeFiles({
45+
'src/styles.css': `h1 { background: url('./test.svg')}`,
46+
'src/test.svg': `<svg xmlns="http://www.w3.org/2000/svg">
47+
<text x="20" y="20" font-size="20" fill="red">Hello World</text>
48+
</svg>`,
49+
});
50+
51+
harness.useTarget('serve', {
52+
...BASE_OPTIONS,
53+
headers: {
54+
'x-custom': 'foo',
55+
},
56+
});
57+
58+
const { result, response } = await executeOnceAndFetch(harness, '/media/test.svg');
59+
60+
expect(result?.success).toBeTrue();
61+
expect(await response?.headers.get('x-custom')).toBe('foo');
62+
});
63+
});
64+
},
65+
);

packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ export async function setupServer(
547547
outputFiles,
548548
assets,
549549
ssr,
550+
extraHeaders: serverOptions.headers,
550551
external: externalMetadata.explicit,
551552
indexHtmlTransformer,
552553
extensionMiddleware,

0 commit comments

Comments
 (0)