-
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-devkit/build-angular): construct SSR request URL using s…
…erver resolvedUrls With vite `header.host` is undefined when SSL is enabled. This resulted in an invalid URL to be constructed. Closes #26652
- Loading branch information
1 parent
7f86757
commit a5d4735
Showing
3 changed files
with
85 additions
and
3 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
80 changes: 80 additions & 0 deletions
80
tests/legacy-cli/e2e/tests/commands/serve/ssr-http-requests-assets.ts
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,80 @@ | ||
import assert from 'node:assert'; | ||
|
||
import { killAllProcesses, ng } from '../../../utils/process'; | ||
import { rimraf, writeMultipleFiles } from '../../../utils/fs'; | ||
import { installWorkspacePackages } from '../../../utils/packages'; | ||
import { ngServe, useSha } from '../../../utils/project'; | ||
|
||
export default async function () { | ||
// Forcibly remove in case another test doesn't clean itself up. | ||
await rimraf('node_modules/@angular/ssr'); | ||
await ng('add', '@angular/ssr', '--skip-confirmation'); | ||
await useSha(); | ||
await installWorkspacePackages(); | ||
|
||
await writeMultipleFiles({ | ||
// Add http client and route | ||
'src/app/app.config.ts': ` | ||
import { ApplicationConfig } from '@angular/core'; | ||
import { provideRouter } from '@angular/router'; | ||
import { HomeComponent } from './home/home.component'; | ||
import { provideClientHydration } from '@angular/platform-browser'; | ||
import { provideHttpClient, withFetch } from '@angular/common/http'; | ||
export const appConfig: ApplicationConfig = { | ||
providers: [ | ||
provideRouter([{ | ||
path: '', | ||
component: HomeComponent, | ||
}]), | ||
provideClientHydration(), | ||
provideHttpClient(withFetch()), | ||
], | ||
}; | ||
`, | ||
// Add asset | ||
'src/assets/media.json': JSON.stringify({ dataFromAssets: true }), | ||
// Update component to do an HTTP call to asset. | ||
'src/app/app.component.ts': ` | ||
import { Component, inject } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { RouterOutlet } from '@angular/router'; | ||
import { HttpClient } from '@angular/common/http'; | ||
@Component({ | ||
selector: 'app-root', | ||
standalone: true, | ||
imports: [CommonModule, RouterOutlet], | ||
template: \` | ||
<p>{{ data | json }}</p> | ||
<router-outlet></router-outlet> | ||
\`, | ||
}) | ||
export class AppComponent { | ||
data: any; | ||
constructor() { | ||
const http = inject(HttpClient); | ||
http.get('/assets/media.json').toPromise().then((d) => { | ||
this.data = d; | ||
}); | ||
} | ||
} | ||
`, | ||
}); | ||
|
||
await ng('generate', 'component', 'home'); | ||
const match = /<p>{[\S\s]*"dataFromAssets":[\s\S]*true[\S\s]*}<\/p>/; | ||
const port = await ngServe('--no-ssl'); | ||
assert.match(await (await fetch(`http://localhost:${port}/`)).text(), match); | ||
|
||
await killAllProcesses(); | ||
|
||
try { | ||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; | ||
const sslPort = await ngServe('--ssl'); | ||
assert.match(await (await fetch(`https://localhost:${sslPort}/`)).text(), match); | ||
} finally { | ||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '1'; | ||
} | ||
} |