Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export function createAngularAssetsMiddleware(
return;
}

// Support HTTP HEAD requests for the virtual output files from the Angular build
if (req.method === 'HEAD' && outputFiles.get(pathname)?.servable) {
// While a GET will also generate content, the rest of the response is equivalent
req.method = 'GET';
}

// Resource files are handled directly.
// Global stylesheets (CSS files) are currently considered resources to workaround
// dev server sourcemap issues with stylesheets.
Expand Down
25 changes: 25 additions & 0 deletions tests/legacy-cli/e2e/tests/commands/serve/head-request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ngServe } from '../../../utils/project';

export default async function () {
const port = await ngServe();
// HTML
await checkHeadForUrl(`http://localhost:${port}/index.html`);
// Generated JS
await checkHeadForUrl(`http://localhost:${port}/main.js`);
// Generated CSS
await checkHeadForUrl(`http://localhost:${port}/styles.css`);
// Configured asset
await checkHeadForUrl(`http://localhost:${port}/favicon.ico`);
}

async function checkHeadForUrl(url: string): Promise<void> {
const result = await fetch(url, { method: 'HEAD' });
const content = await result.blob();

if (content.size !== 0) {
throw new Error(`Expected "size" to be "0" but got "${content.size}".`);
}
if (result.status !== 200) {
throw new Error(`Expected "status" to be "200" but got "${result.status}".`);
}
}
3 changes: 3 additions & 0 deletions tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export default async function () {
`,
);

// Ensure localize package is not present initially
await uninstallPackage('@angular/localize');

// Should fail if `@angular/localize` is missing
const { message: message1 } = await expectToFail(() => ng('extract-i18n'));
if (!message1.includes(`i18n extraction requires the '@angular/localize' package.`)) {
Expand Down