Skip to content

feat: Migrate to Cloudflare Workers - #238

Merged
hhvrc merged 14 commits into
developfrom
feat/cloudflare-workers
Aug 6, 2026
Merged

feat: Migrate to Cloudflare Workers#238
hhvrc merged 14 commits into
developfrom
feat/cloudflare-workers

Conversation

@hhvrc

@hhvrc hhvrc commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Moves the Cloudflare deploy from Pages to Workers, and drops Pages support.

Why

sveltejs/kit#16604 removes Pages support from @sveltejs/adapter-cloudflare entirely (breaking, targets SvelteKit v3).
Staying on Pages means pinning the adapter forever.

Cloudflare's own Workers best practices say it plainly: "If you are starting a new project, use Workers instead of Pages."

There's no EOL date, but all future investment goes to Workers, and Pages still lacks Durable Objects, Cron Triggers, Queues, and decent observability.

See the migration guide.

Changes

  • Renamed wrangler.workers.jsonc to wrangler.jsonc, deleted the Pages config. It's auto-discovered, so no --config flag and no two files to hand-sync.
  • Worker renamed to openshock-app.
  • Dropped CF_PAGES detection from vite.config.ts, and renamed isWorkersCI to isCloudflare. The Node adapter still covers local/Docker/selfhost.
  • Dropped nodejs_als, which is redundant under nodejs_compat at our compatibility date.
  • Submodule URL switched to HTTPS. Workers Builds clones with a GitHub App token and has no SSH key, so git@ fails the build. If you want SSH locally:
    git config --local url."git@github.com:".insteadOf "https://github.com/"
  • Reverts f636c8b (sdk-trace-base plus a hand-rolled context manager). That only existed to work around the Pages bundler. The Workers bundler resolves context-async-hooks fine via its node-built-in-modules:async_hooks shim, verified in a wrangler deploy --dry-run bundle. Removes ~40 lines of custom code.
  • _headers and _redirects stay. Both are supported on Workers static assets.

Required before merge

Dashboard changes. Builds fail without them:

  1. Rename the Worker to openshock-app. The config name has to match or the build errors out.
  2. Set the deploy command to plain wrangler deploy. It currently passes --config wrangler.workers.jsonc, which no longer exists.
  3. Delete the old Pages project.

Follow-ups

Out of scope here:

  • PUBLIC_SIGNOZ_LOGS_ENABLED is a build-time static import, so server tracing gets dead-code eliminated unless it's set as a build variable. Set it to true, not 1. Four call sites parse it three different ways, and 1 would turn telemetry on while leaving the consent prompt dark.
  • BatchSpanProcessor flushes on a timer with no waitUntil wiring, so spans can be lost when a Workers isolate is evicted. Unmeasured so far.

Summary by CodeRabbit

  • New Features

    • Added support for deploying the application as a Cloudflare Worker, including static assets, observability, logging, tracing, and source-map uploads.
    • Added generated environment configuration support for Cloudflare Worker deployments.
    • Improved server-side tracing integration and reliability.
  • Documentation

    • Documented the pnpx regen-api API client generation command.
    • Added self-hosting guidance, including Cloudflare Workers deployment instructions.
    • Updated submodule setup instructions and streamlined local tool installation guidance.

hhvrc and others added 8 commits August 4, 2026 09:57
…lemetry gating

nodejs_compat already provides AsyncLocalStorage at our compatibility date
(>= 2024-09-23 enables nodejs_compat_v2), so nodejs_als was a no-op in both
wrangler configs.

Move @opentelemetry/api and @opentelemetry/sdk-trace-node to dependencies,
alongside the other seven @opentelemetry/* packages.

Document that PUBLIC_SIGNOZ_LOGS_ENABLED is intentionally one switch for all
telemetry signals despite its name, and that being a $env/static/public import
means the whole tracing block is dead-code eliminated unless the flag is set in
the build environment -- not just at runtime.

Note in the CSP comment that the _headers X-Frame-Options fallback for
prerendered pages is Cloudflare-only: adapter-node serves prerendered HTML
through sirv before the SvelteKit handler, so hooks.server.ts never runs for it.
Moot while prerender = false at the root layout.
Workers Builds is the only Cloudflare deploy path now, so the dual-config
arrangement is gone: wrangler.workers.jsonc is promoted to wrangler.jsonc,
which wrangler and @sveltejs/adapter-cloudflare both auto-discover. The
adapter selects Workers output over Pages output because the config declares
main/assets and no pages_build_output_dir, so the explicit `config` option and
the `--config` deploy flag are no longer needed, and there are no longer two
files whose compatibility settings must be hand-synced.

Drop CF_PAGES detection from vite.config.ts and rename isWorkersCI to
isCloudflare now that it is the only Cloudflare branch. This also removes the
CF_PAGES_COMMIT_SHA fallback in getGitHash().

_headers and _redirects are kept — Workers static assets support both, and
adapter-cloudflare copies them from the project root in either mode.
develop deliberately stripped the Cloudflare Workers deployment (c4f549d) so
this branch owns it, so the deletions it carries for wrangler.jsonc,
src/worker-configuration.d.ts, and the wrangler devDependency are reverted here
-- they are this branch's reason to exist.

Conflict resolutions:

- package.json: keep @opentelemetry/sdk-trace-node and drop develop's swap to
  sdk-trace-base (see below). Restore the wrangler devDependency, which
  adapter-cloudflare imports (unstable_readConfig) and `wrangler deploy` needs.
- vite.config.ts: keep develop's adapter comment; the Workers/Node split itself
  is unchanged.
- wrangler.jsonc: keep ours (deleted on develop).
- src/worker-configuration.d.ts: keep ours (deleted on develop).
- pnpm-lock.yaml: regenerated.

f636c8b swapped sdk-trace-node for sdk-trace-base plus a hand-rolled
AsyncLocalStorage context manager because the Cloudflare Pages Functions bundler
could not resolve @opentelemetry/context-async-hooks' bare require("async_hooks")
and require("events"). That reason does not apply here: Pages support is gone as
of 42c51ab, and wrangler's Workers bundler maps those bare requires onto the
builtin via a node-built-in-modules:async_hooks shim -- confirmed by inspecting
a `wrangler deploy --dry-run` bundle. Reverting drops ~40 lines of custom
ContextManager, including a subtle bind() that forwards dynamic `this`, in favour
of the maintained upstream class. NodeTracerProvider.register() only needs
AsyncLocalStorage, which nodejs_compat supplies; the sibling
AsyncHooksContextManager that needs the unsupported createHook is imported but
never constructed.
@hhvrc
hhvrc requested a lite review from Copilot August 6, 2026 10:35
@hhvrc hhvrc self-assigned this Aug 6, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 6, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
openshock-app c510e04 Aug 06 2026, 12:18 PM

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the project’s Cloudflare deployment from Pages to Workers (Workers Builds), removing Pages-specific configuration and adjusting build/runtime detection and tracing setup to align with the Workers toolchain.

Changes:

  • Added a wrangler.jsonc Workers configuration (auto-discovered) and updated Cloudflare detection in vite.config.ts to rely on WORKERS_CI.
  • Simplified server-side OpenTelemetry tracing bootstrap by switching to @opentelemetry/sdk-trace-node’s NodeTracerProvider.
  • Updated repo tooling/docs: submodule URL to HTTPS, README instructions, and dependency/lockfile updates (including adding wrangler).

Reviewed changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
wrangler.jsonc Introduces the Workers (Wrangler) config for Workers Builds deployment.
vite.config.ts Updates Cloudflare CI detection and related build behavior (adapter selection, git SHA, production gating).
src/worker-configuration.d.ts Adds generated Wrangler types for Worker bindings/env.
src/instrumentation.server.ts Switches tracing provider to NodeTracerProvider for Workers-friendly bundling/runtime.
README.md Updates setup/self-hosting notes and API client generation command documentation.
package.json Adjusts dependencies (adds wrangler, moves/adds OTel packages for node tracing).
pnpm-lock.yaml Locks new/updated dependencies introduced by the migration.
.gitmodules Switches submodule URL from SSH to HTTPS to support Workers Builds cloning.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread vite.config.ts Outdated
Comment thread wrangler.jsonc
Copilot AI review requested due to automatic review settings August 6, 2026 10:45
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@hhvrc, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 48 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5f723bfd-26ae-4995-b32d-30b9aab4715a

📥 Commits

Reviewing files that changed from the base of the PR and between 0809d4e and c510e04.

📒 Files selected for processing (1)
  • README.md
📝 Walkthrough

Walkthrough

The pull request adds Cloudflare Worker deployment configuration, generated environment typings, and Workers CI detection. It changes server tracing to use NodeTracerProvider, updates runtime dependencies, and revises repository setup and self-hosting documentation.

Changes

Cloudflare runtime and project setup

Layer / File(s) Summary
Worker deployment and environment configuration
src/worker-configuration.d.ts, wrangler.jsonc, vite.config.ts, README.md
Adds Cloudflare Worker configuration and environment typings. Updates Workers CI detection, production mode detection, commit lookup, and self-hosting guidance.
Node tracing runtime
src/instrumentation.server.ts, package.json
Replaces the custom context manager and BasicTracerProvider with NodeTracerProvider and provider.register(). Moves OpenTelemetry packages to runtime dependencies.
Repository setup and generation instructions
.gitmodules, README.md
Changes the submodule URL to HTTPS and documents API generation, setup prerequisites, and SSH rewrite guidance.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: copilot, lucheart

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: migrating the Cloudflare deployment from Pages to Workers.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/cloudflare-workers

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Generated file
Suppressed comments (2)

src/instrumentation.server.ts:38

  • Telemetry gating for server spans treats PUBLIC_SIGNOZ_LOGS_ENABLED='1' as enabled, but the consent prompt (src/lib/telemetry/consent-prompt.ts:14) only enables when the flag is exactly 'true'. This can lead to inconsistent behavior when a deploy sets the flag to '1' (server spans on, but no consent prompt). Consider standardizing on a single value (preferably 'true').
const enabled = PUBLIC_SIGNOZ_LOGS_ENABLED === 'true' || PUBLIC_SIGNOZ_LOGS_ENABLED === '1';

README.md:42

  • README now recommends a global Git config rewrite from https://github.com/ to git@github.com:, which can unexpectedly affect all repositories on a developer machine. The PR description suggests using a repo-local rewrite instead; the docs should match that safer default.
To clone the project you may need to rewrite git HTTPS urls to SSH for the submodule checkout to work on your machine.
You can do this with `git config --global url."git@github.com:".insteadOf "https://github.com/"`

Copilot AI review requested due to automatic review settings August 6, 2026 10:49

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Line 37: Update the README API client generation command from pnpx regen-api
to pnpm run regen-api so it invokes the local regen-api package script.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5ac748ae-30ea-4275-b6d5-fc6c64181196

📥 Commits

Reviewing files that changed from the base of the PR and between b8c1d66 and 3da4c1e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • .gitmodules
  • README.md
  • package.json
  • src/instrumentation.server.ts
  • src/worker-configuration.d.ts
  • vite.config.ts
  • wrangler.jsonc

Comment thread README.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Generated file
Suppressed comments (2)

README.md:165

  • The README says the project can be deployed to Workers with Wrangler, but the build selects adapterCloudflare() only when WORKERS_CI is set (see vite.config.ts), and wrangler.jsonc expects .svelte-kit/cloudflare/_worker.js. Without guidance, a local pnpm build + wrangler deploy will likely produce Node adapter output instead of the required Workers output.
## Selfhosting

A guide to selfhost can be found [on the wiki.](https://wiki.openshock.org/guides/selfhosting)
Alternatively you can deploy it to cloudflare workers using wrangler (or forking it).

README.md:42

  • These instructions suggest rewriting all GitHub HTTPS URLs globally, which is a broad side-effect and doesn’t match the new motivation (submodule now uses HTTPS by default). Consider making this optional and scoped to the repo via --local.
To clone the project you may need to rewrite git HTTPS urls to SSH for the submodule checkout to work on your machine.
You can do this with `git config --global url."git@github.com:".insteadOf "https://github.com/"`

Copilot AI review requested due to automatic review settings August 6, 2026 10:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Generated file
Suppressed comments (2)

README.md:164

  • Minor wording/capitalization issues in the self-hosting section ("Selfhosting"/"selfhost" and "cloudflare"/"workers" naming). Cleaning this up makes the docs look more polished and consistent.
## Selfhosting

A guide to selfhost can be found [on the wiki.](https://wiki.openshock.org/guides/selfhosting)
Alternatively you can deploy it to cloudflare workers using wrangler (or forking it).

README.md:42

  • This reads like SSH rewriting is required for the submodule to work, but .gitmodules now uses an HTTPS URL so checkout should work by default. Consider rephrasing this as an optional tip for developers who prefer SSH, and avoid a global rewrite that may break other GitHub HTTPS workflows.
To clone the project you may need to rewrite git HTTPS urls to SSH for the submodule checkout to work on your machine.
You can do this with `git config --global url."git@github.com:".insteadOf "https://github.com/"`

Copilot AI review requested due to automatic review settings August 6, 2026 11:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Generated file
Suppressed comments (2)

README.md:45

  • The README implies HTTPS→SSH rewriting is required for the submodule to clone, and suggests a global rewrite. Since the submodule URL is now HTTPS specifically to work in Cloudflare Workers Builds, it’s safer to present SSH rewriting as optional and keep it repo-local (or at least not recommended globally).
To clone the project you may need to rewrite git HTTPS urls to SSH for the submodule checkout to work on your machine.
You can do this with `git config --global url."git@github.com:".insteadOf "https://github.com/"`

To get started with development, you will need to have **Node.js** and **pnpm** installed.
We recommend using a node version manager of your choice.

README.md:165

  • Minor wording/capitalization issues in the new self-hosting section ("Selfhosting", "selfhost", and "cloudflare workers"). This section reads more cleanly with standard hyphenation and proper nouns capitalized.
## Selfhosting

A guide to selfhost can be found [on the wiki.](https://wiki.openshock.org/guides/selfhosting)
Alternatively you can deploy it to cloudflare workers using wrangler (or forking it).

@hhvrc
hhvrc merged commit b3d8dc8 into develop Aug 6, 2026
13 checks passed
@hhvrc
hhvrc deleted the feat/cloudflare-workers branch August 6, 2026 12:20
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.

3 participants