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
10 changes: 10 additions & 0 deletions .changeset/fix-angular-localhost-ssr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"create-cloudflare": patch
"wrangler": patch
---

Fix Angular scaffolding to allow localhost SSR in development mode

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.`

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.
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ function getFrameworkTestConfig(pm: string): NamedFrameworkTestConfig[] {
},
nodeCompat: false,
flags: ["--style", "sass"],
// TODO: currently the Angular tests are failing with `URL with hostname "localhost" is not allowed.`
// we need to investigate this so that we can un-quarantine the Angular tests
quarantine: true,
},
{
name: "angular:workers",
Expand All @@ -189,9 +186,6 @@ function getFrameworkTestConfig(pm: string): NamedFrameworkTestConfig[] {
},
nodeCompat: false,
flags: ["--style", "sass"],
// TODO: currently the Angular tests are failing with `URL with hostname "localhost" is not allowed.`
// we need to investigate this so that we can un-quarantine the Angular tests
quarantine: true,
},
{
name: "gatsby:pages",
Expand Down Expand Up @@ -790,9 +784,6 @@ function getExperimentalFrameworkTestConfig(
nodeCompat: false,
flags: ["--style", "sass"],
verifyTypes: false,
// TODO: currently the Angular tests are failing with `URL with hostname "localhost" is not allowed.`
// we need to investigate this so that we can un-quarantine the Angular tests
quarantine: true,
},
{
name: "nuxt:workers",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { AngularAppEngine, createRequestHandler } from '@angular/ssr';

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

/**
* This is a request handler used by the Angular CLI (dev-server and during build).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { AngularAppEngine, createRequestHandler } from '@angular/ssr';

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

/**
* This is a request handler used by the Angular CLI (dev-server and during build).
Expand Down
6 changes: 5 additions & 1 deletion packages/wrangler/src/autoconfig/frameworks/angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ async function overrideServerFile() {
dedent`
import { AngularAppEngine, createRequestHandler } from '@angular/ssr';

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

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