Skip to content

Deploy on Cloudflare Pages

1. Create the Pages project

Create a fork of the Set repository. In the Cloudflare dashboard, create a Pages project, import the fork, and set:

  • Production branch: master
  • Framework preset: Nuxt
  • Build command: pnpm build
  • Build output directory: dist

Create the project so settings become available.

Cancel the first auto-deploy if needed

If a deploy starts before you finish bindings and variables, open the deployment list, click Cancel, finish setup, then deploy again.

2. Create resources and bind them

Create the Cloudflare resources you need, then open the Pages project → Settings → Bindings and add them. Binding = connect a resource to Set under a fixed name.

Binding nameProductRequired?What it is
DBD1YesStores links
KVKVYesSpeeds up redirects
ANALYTICSAnalytics EngineRecommendedVisit stats
R2R2OptionalBackups and social images
AIWorkers AIOptionalAI suggestions

Analytics is optional. Setup: Analytics and Realtime.

Required compatibility flag

Under Settings → Functions → Compatibility Flags, add nodejs_compat for both Production and Preview. Set needs this flag to run on Pages.

3. Variables and secrets

Under Settings → Variables and Secrets, add the build deployment configuration below. The two IDs are required for D1 migration and deployment configuration generation.

Build variableRequired?What to put
DEPLOY_D1_DATABASE_IDYesD1 database ID (from the D1 detail page)
DEPLOY_KV_NAMESPACE_IDYesKV namespace ID (from the KV detail page)
DEPLOY_KV_PREVIEW_NAMESPACE_IDNoPreview KV namespace ID; defaults to DEPLOY_KV_NAMESPACE_ID
DEPLOY_D1_DATABASE_NAMENoD1 database name; defaults to sink
DEPLOY_ANALYTICS_DATASETNoAnalytics Engine dataset; defaults to sink_multitenant (also sets NUXT_DATASET)

Also configure Pages Build / Wrangler authentication for the Production environment. Pages does not provide these variables automatically:

Authentication variableTypeWhat to put
CLOUDFLARE_API_TOKENEncrypted secretToken used by the postbuild remote D1 migration. Git builds need at least Account → D1 → Edit. If the same token runs pnpm deploy:pages externally, also grant Account → Cloudflare Pages → Edit
CLOUDFLARE_ACCOUNT_IDVariableCloudflare account ID. Wrangler defines it as optional, but this project does not set account_id, so configure it for stable non-interactive builds

CLOUDFLARE_ACCOUNT_ID may have the same value as NUXT_CF_ACCOUNT_ID, but both variable names must be set separately. Preview builds skip the migration, so these authentication variables are not needed in the Preview environment.

Add runtime configuration separately in the same dashboard section:

Runtime variableTypeWhat to put
NUXT_AUTH_SECRETEncrypted secretRandom secret of at least 32 characters
NUXT_AUTH_BASE_URLVariableExact HTTPS origin of the dashboard app
NUXT_APP_HOSTNAMEVariableDashboard hostname
NUXT_SHORT_LINK_HOSTNAMESVariableComma-separated short-link hostnames
NUXT_CF_ACCOUNT_IDVariableCloudflare account ID (for analytics)
NUXT_CF_API_TOKENEncrypted secretCustom Token with Account → Account Analytics → Read only

How to create the analytics token: Cloudflare dashboard → profile icon → My ProfileAPI TokensCreate TokenCustom Token → permission Account → Account Analytics → Read.

Pages exposes this dashboard variable set to both build and runtime, but each group has a distinct role: DEPLOY_* values generate deployment configuration, CLOUDFLARE_* values authenticate Wrangler, and NUXT_* values configure the running application. For Pages, add R2 only under Bindings; do not add R2 DEPLOY_* variables. More options: configuration.

The repository's postbuild script runs the remote D1 migration only when Pages builds the master branch (CF_PAGES=1 and CF_PAGES_BRANCH=master). Therefore, a successful main-branch Pages build updates the D1 schema automatically; preview-branch builds do not.

4. Deploy and first use

Start a deployment from master and wait until it finishes.

For a manual CLI deployment, build first. pnpm deploy:pages assumes dist already exists: it generates wrangler.deploy.jsonc from the DEPLOY_* values, applies remote D1 migrations, and then uploads dist with Wrangler. It does not run the application build.

  1. Complete the expiring one-time bootstrap described in multitenant operations
  2. Remove the bootstrap token variables
  3. Sign in as the first owner and create a link

Manual backups work on Pages; automatic daily backups are configured for Workers only in this repo.