Skip to content

Cf worker setup#295

Open
eneajaho wants to merge 6 commits into
mainfrom
cf-worker-setup
Open

Cf worker setup#295
eneajaho wants to merge 6 commits into
mainfrom
cf-worker-setup

Conversation

@eneajaho

Copy link
Copy Markdown
Collaborator

No description provided.

eneajaho and others added 6 commits June 17, 2026 18:32
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Dissolves the standalone cf-worker NX project and consolidates all
Cloudflare Worker build targets (build-cf-worker, preview-cf-worker,
deploy-cf-worker, cf-typegen) directly into the movies project.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Move the movies app SSR onto the @angular/ssr AngularAppEngine +
createRequestHandler flow (app.routes.server.ts), replacing the
zone-less CommonEngine routing path.

Fix two SSR runtime bugs surfaced on the Worker:
- The CF FastSVG loader fetched icons from `${origin}/${name}.svg`,
  which missed the static asset, fell through to the `**` route and
  redirected to `/page-not-found`. fetch() followed the redirect and
  triggered a full SSR render per icon, recursing exponentially and
  exhausting the Worker subrequest budget (which also broke TMDB
  fetches). Fetch from `/assets/svg-icons/${name}.svg` instead.
- Guard the RxState patch() reducers (movie/discover/person state)
  with `|| {}` so the first/loading emission no longer logs
  "Patch: original value undefined is not an object." warnings.

Drop the leftover zone-less routing/zone helpers.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Allow all hosts with trustProxyHeaders so the Worker renders behind
Cloudflare's proxy, set NG_ALLOWED_HOSTS / NODE_VERSION wrangler vars,
and drop the dead withDisabledInitialNavigation comments.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Wrap the Cloudflare Worker request handler with a Workers KV page
cache (binding `ssr_cache`): GET requests that render to 200 HTML are
stored with a 120s expirationTtl and served straight from KV on the
next hit. Redirects, non-GET and non-HTML responses bypass the cache.

A build-id (generated by scripts/generate-build-id.mjs before each
cf-worker build) is stored as KV metadata so a new deploy ignores
stale entries instead of serving HTML that references old asset hashes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment on lines +80 to +88
// setTimeout(() => {
// this.router.navigate([
// // The pathname route seems to work correctly on SSR but when pre-rendering it is an empty string.
// // We have to fall back to document URL as a fix.
// fallbackRouteToDefault(
// this.document.location.pathname || this.document.URL,
// ),
// ]);
// });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a left over? If yes, please lets delete it.

Comment on lines +64 to +68
// setOptions(options: RxInputType<Record<string, string>>) {
// this.effects.register(coerceObservable(options), (queryParams) =>
// this.router.navigate([], { queryParams }),
// );
// }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left over?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice this is cleaned up now! :)

Comment on lines +69 to +76
// {
// provide: APP_INITIALIZER,
// useFactory: () => (): Promise<void> =>
// new Promise<void>((resolve) => {
// setTimeout(() => resolve());
// }),
// multi: true,
// },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left over?

allowedHosts: readonly string[];
supportedLocales: Readonly<Record<string, string>>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
entryPoints: Readonly<Record<string, (() => Promise<any>) | undefined>>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know the shape of the entryPoint so typing and linting is in a good shape pls?

Comment on lines +10 to +11
// hack to make it work - not needed on normal angular setup
ɵsetAngularAppEngineManifest(manifest);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add some more comments to make it also clear what the hack does and why it it needed?

@BioPhoton BioPhoton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice we progress with the SSR setup!

I found some leftover commented out code and a eslint disabling. other than this with a small PR description it looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants