-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular/build): support HTTP HEAD requests for virtual output files
When using the development server, HTTP HEAD requests will now correctly respond for the virtual output files generated from the Angular build system. Previously Vite only handled GET requests for the files. While HEAD requests are not common in development workflows, it can be needed in more complex cases with additional servers/proxies/etc. during development. (cherry picked from commit f6b7cd9)
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}".`); | ||
} | ||
} |