ekumanov/flarum-ext-edge-cache
Composer 安装命令:
composer require ekumanov/flarum-ext-edge-cache
包简介
Cookieless guest page views + CSRF retry shim, enabling safe Cloudflare edge caching of guest HTML.
README 文档
README
Makes guest page views cookieless so Cloudflare can safely cache guest HTML at the edge, plus a client-side CSRF retry shim so auth flows survive landing on a cached page. Requires Flarum 2.0.
Installation
composer require ekumanov/flarum-ext-edge-cache
Components
- EdgeCacheMiddleware (forum frontend, inserted before
StartSession— StartSession attaches cookies on the response's way OUT, so only an outer middleware can strip them): credential-less GET/HEAD on allowlisted paths → strip ALLSet-Cookie+X-CSRF-Token, emitCache-Control: public, s-maxage=300, max-age=0, must-revalidateand aServer-Timing: originheader. All other forum HTML → explicitCache-Control: private, no-store. - JS retry shim: on
400 csrf_token_mismatch, single-flightGET /api(refreshes session cookie + token via core's response-header update), retry the original request once. - CSRF exemption for
forum-widgets.guest-heartbeat, the guest presence beacon of ekumanov/flarum-ext-forum-widgets (spoofable anyway, and the highest-frequency 400 source on cached pages). A no-op when that extension isn't installed.
The matching Cloudflare Cache Rule (v1)
Expression: host eq "example.com" AND starts_with(path, "/d/") AND
method GET AND NOT (cookie contains "flarum_session" OR cookie contains
"flarum_remember") → Eligible for cache, Edge TTL: respect origin,
Browser TTL: respect origin. Adjust the host and the path prefix to your
install (e.g. /forum/d/ when Flarum is mounted under /forum).
Invariants — read before changing anything
- The middleware path allowlist and the CF rule scope move in lockstep, in the same deploy.
- API responses must keep their Set-Cookie forever (heartbeat session-dedupe and the shim's refresh GET depend on it). This middleware is forum-only.
/reset,/confirmetc. are server-rendered Blade forms needing their session cookie — permanently denylisted.- Adding any guest-facing language switcher silently poisons the cache (CF
ignores
Vary) — revisit the rule before shipping one. - CSRF 400s never reach flarum.log (KnownError) — monitor nginx access-log double-400s instead.
Rollback order
Disable this extension → clear the Flarum cache and purge the Cloudflare cache immediately (cached HTML referencing a rebuilt forum.js without the shim would otherwise strand guests until TTL expiry). Deleting the CF rule is safe at any point, in any order.
Build
cd js && npm install && npm run build
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-12