Skip to content

Commit 612c0d8

Browse files
committed
fix(@angular-devkit/build-angular): normalize asset source locations in Vite-based development server
The Vite-based development server uses an allow list to permit access to configured assets. This list is checked internally to Vite by uses its normalized path form. To ensure that assets provided by the build are checked correctly on all platforms, the asset list is now normalized with Vite's path normalization prior to being used.
1 parent f816162 commit 612c0d8

File tree

2 files changed

+24
-1
lines changed
  • packages/angular_devkit/build_angular/src/builders/dev-server
  • tests/legacy-cli/e2e/tests/commands/serve

2 files changed

+24
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export async function* serveWithVite(
191191
assetFiles.clear();
192192
if (result.assetFiles) {
193193
for (const asset of result.assetFiles) {
194-
assetFiles.set('/' + normalizePath(asset.destination), asset.source);
194+
assetFiles.set('/' + normalizePath(asset.destination), normalizePath(asset.source));
195195
}
196196
}
197197

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import assert from 'assert';
2+
import { ngServe } from '../../../utils/project';
3+
4+
export default async function () {
5+
const port = await ngServe();
6+
7+
let response = await fetch(`http://localhost:${port}/`, { headers: { 'Accept': 'text/html' } });
8+
assert.strictEqual(response.status, 200);
9+
assert.match(await response.text(), /<app-root><\/app-root>/);
10+
11+
response = await fetch(`http://localhost:${port}/test`, { headers: { 'Accept': 'text/html' } });
12+
assert.strictEqual(response.status, 200);
13+
assert.match(await response.text(), /<app-root><\/app-root>/);
14+
15+
response = await fetch(`http://localhost:${port}/test/abc`, {
16+
headers: { 'Accept': 'text/html' },
17+
});
18+
assert.strictEqual(response.status, 200);
19+
assert.match(await response.text(), /<app-root><\/app-root>/);
20+
21+
response = await fetch(`http://localhost:${port}/favicon.ico`);
22+
assert.strictEqual(response.status, 200);
23+
}

0 commit comments

Comments
 (0)