[MKT-719]:feat/cloudflare workers migration - #2151
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
xabg2
approved these changes
Sep 15, 2026
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


What
Ports the website from the PM2 VM to Cloudflare Workers using the
@opennextjs/cloudflareadapter.This is a pure migration: behaviour is preserved as-is. No SSR→ISR/static
conversions, no cache-control changes, no axios→fetch rewrites.
Nothing is deployed by this PR.
cd.ymlis untouched, so the VM keepsserving production and remains the rollback path.
Why
The VM requires manual capacity and patching, has a single point of failure and
no edge presence. On top of that, the in-memory rate limiting and cache we rely
on today are not correct in a multi-process/multi-isolate world (see below).
Adapter and configuration
@opennextjs/cloudflare1.20.6 +wrangler4.131.2 (≥ 4.36.0 is required forthe Rate Limiting binding).
wrangler.jsonc:nodejs_compat+global_fetch_strictly_public, the assetsbinding and the five rate limiting namespaces.
open-next.config.tsuses the default config — no incremental cache, sincethe site is 100% SSR (141
getServerSideProps, 0getStaticProps).check-envs.jsno longer requires a.env.localon disk (it does not exist inCI/Workers builds) and now warns about variables the code uses but that are
missing from
.env.local.example.build:cf,preview,deploy:cf,cf-typegen.In-memory state → Workers primitives
Workers isolates do not share memory, so the previous limits were effectively
N × limitwithNunknown, and the cache hit rate was undefined.src/utils/rate-limiter.ts→ Rate Limiting binding. The signature is unchanged,so the 4 consuming endpoints need no edits.
src/pages/api/contact.ts→CONTACT_LIMITER.src/lib/github.ts→memory-cachereplaced by the Cache API, same 5 min TTLand the same return shape.
src/utils/get-client-ip.ts: the client IP now comes fromCF-Connecting-IP.req.socket.remoteAddressdoes not exist on Workers, andx-forwarded-forisclient-writable.
Images
There is no Next.js image optimizer on Workers, so resizing is delegated to
Cloudflare Image Resizing through a custom loader (
image-loader.ts, wired up innext.config.js). The loader is a no-op outside production so local dev isunaffected. Note that a custom loader ignores
remotePatterns— allowedexternal origins must be authorised in the Cloudflare dashboard (kept in
next.config.jsfor the non-Workers build path).Cookies
src/lib/cookies.tsnow derives thesecureflag fromx-forwarded-protoinstead of letting the
cookieslibrary infer it from the socket, which is notreliable behind the Cloudflare proxy. Falls back to
NODE_ENV === 'production'when the header is absent.