Skip to content

Commit 3d6e421

Browse files
[C3/wrangler] Fix Angular localhost SSR blocking in development mode (#12648)
1 parent 275ff4e commit 3d6e421

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"create-cloudflare": patch
3+
"wrangler": patch
4+
---
5+
6+
Fix Angular scaffolding to allow localhost SSR in development mode
7+
8+
Recent versions of Angular's `AngularAppEngine` block serving SSR on `localhost` by default. This caused `wrangler dev` / `wrangler pages dev` to fail with `URL with hostname "localhost" is not allowed.`
9+
10+
The fix passes `allowedHosts: ["localhost"]` to the `AngularAppEngine` constructor in `server.ts`, which is safe to do even in production since Cloudflare will already restrict which host is allowed.

packages/create-cloudflare/e2e/tests/frameworks/test-config.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ function getFrameworkTestConfig(pm: string): NamedFrameworkTestConfig[] {
167167
},
168168
nodeCompat: false,
169169
flags: ["--style", "sass"],
170-
// TODO: currently the Angular tests are failing with `URL with hostname "localhost" is not allowed.`
171-
// we need to investigate this so that we can un-quarantine the Angular tests
172-
quarantine: true,
173170
},
174171
{
175172
name: "angular:workers",
@@ -189,9 +186,6 @@ function getFrameworkTestConfig(pm: string): NamedFrameworkTestConfig[] {
189186
},
190187
nodeCompat: false,
191188
flags: ["--style", "sass"],
192-
// TODO: currently the Angular tests are failing with `URL with hostname "localhost" is not allowed.`
193-
// we need to investigate this so that we can un-quarantine the Angular tests
194-
quarantine: true,
195189
},
196190
{
197191
name: "gatsby:pages",
@@ -790,9 +784,6 @@ function getExperimentalFrameworkTestConfig(
790784
nodeCompat: false,
791785
flags: ["--style", "sass"],
792786
verifyTypes: false,
793-
// TODO: currently the Angular tests are failing with `URL with hostname "localhost" is not allowed.`
794-
// we need to investigate this so that we can un-quarantine the Angular tests
795-
quarantine: true,
796787
},
797788
{
798789
name: "nuxt:workers",

packages/create-cloudflare/templates/angular/pages/templates/src/server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { AngularAppEngine, createRequestHandler } from '@angular/ssr';
22

3-
const angularApp = new AngularAppEngine();
3+
const angularApp = new AngularAppEngine({
4+
// It is safe to set allow `localhost`, so that SSR can run in local development,
5+
// as, in production, Cloudflare will ensure that `localhost` is not the host.
6+
allowedHosts: ['localhost'],
7+
});
48

59
/**
610
* This is a request handler used by the Angular CLI (dev-server and during build).

packages/create-cloudflare/templates/angular/workers/templates/src/server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { AngularAppEngine, createRequestHandler } from '@angular/ssr';
22

3-
const angularApp = new AngularAppEngine();
3+
const angularApp = new AngularAppEngine({
4+
// It is safe to set allow `localhost`, so that SSR can run in local development,
5+
// as, in production, Cloudflare will ensure that `localhost` is not the host.
6+
allowedHosts: ['localhost'],
7+
});
48

59
/**
610
* This is a request handler used by the Angular CLI (dev-server and during build).

packages/wrangler/src/autoconfig/frameworks/angular.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ async function overrideServerFile() {
6060
dedent`
6161
import { AngularAppEngine, createRequestHandler } from '@angular/ssr';
6262
63-
const angularApp = new AngularAppEngine();
63+
const angularApp = new AngularAppEngine({
64+
// It is safe to set allow \`localhost\`, so that SSR can run in local development,
65+
// as, in production, Cloudflare will ensure that \`localhost\` is not the host.
66+
allowedHosts: ['localhost'],
67+
});
6468
6569
/**
6670
* This is a request handler used by the Angular CLI (dev-server and during build).

0 commit comments

Comments
 (0)