Skip to content

Latest commit

 

History

History

codius-astro

Codius Astro

🧩 Components

Cloudflare Pages

🔧 Setup

Cloudflare Account

Create a Cloudflare account.

You will need a paid plan and enable Workers for Platforms1.

Create a Cloudflare API Token with permission to Edit Workers Scripts.

Add CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN as project secrets.

D1 Database

Create a Cloudflare D1 Database for managing user and worker data.

From monorepo root:

pnpm --filter codius-astro d1 create <your-d1-db-name>

Add the D1 database_name and database_id to [[wrangler.env]] in wrangler.toml in the following sections:

  • [[d1_databases]] (for local development)
  • [[env.preview.d1_databases]] (for preview deployments)
  • [[env.production.d1_databases]] (for production deployments)

See Workers Environments and Pages Branch deployment controls documentation for more information about managing production and preview environments for your Cloudflare Pages project.

Apply migrations to your database:

pnpm --filter codius-astro drizzle-kit generate
pnpm --filter codius-astro d1 migrations apply <your-d1-db-name> --local
pnpm --filter codius-astro d1 migrations apply <your-d1-db-name> --remote

Note: Rollback local migrations by deleting the state files with the following command:

rm packages/codius-astro/.wrangler/state/v3/d1/miniflare-D1DatabaseObject/*

GitHub OAuth App

You'll need to create a GitHub OAuth App to allow users to login with GitHub.

Authorization callback URL should be either:

  • http://localhost:8788/login/github/callback for local development or
  • https://<your-pages-domain>/login/github/callback

Example:

GitHub OAuth app

Note: Use 127.0.0.1:8788 if running with pnpm run dev instead of pnpm run preview

Add GITHUB_APP_NAME and GITHUB_CLIENT_ID as environment variables with the values from the GitHub OAuth App.

Add GITHUB_CLIENT_SECRET as a project secret with the value from the GitHub OAuth App.

GitHub Access Token

You'll need to create a GitHub Access Token with Read and Write access to Actions in order for codius-astro to deploy workers via its GitHub Actions workflow.

GitHub Access Token

Add GITHUB_ACCESS_TOKEN as a project secret with the value from the GitHub Access Token.

GitHub Webhook

You'll need to create a GitHub repository webhook to handle Workflow jobs and Workflows runs events.

For Payload URL, use either:

  • https://smee.io/<your-smee-path> for local development with Smee.io or
  • https://<your-pages-domain>/webhooks/github/workflow-job

Generate a Secret for the webhook and add GITHUB_WEBHOOK_SECRET as a project secret.

Example:

Webhook settings

Webhook event

Stripe

You'll need to create a Stripe account and get your Stripe Secret Key.

Create a Stripe Product and Price for topping up worker balances.

The Price should be of type Customer chooses price.

Add STRIPE_SECRET_KEY and STRIPE_TOPUP_PRICE_ID as project secrets with the values from Stripe.

Environment Variables

Environment variables are managed in wrangler.toml.

CF_DISPATCH_NAMESPACE

The namespace of the dispatch-worker deployed to Cloudflare Workers.

DISPATCH_WORKER_HOSTNAME

The hostname of the dispatch-worker deployed to Cloudflare Workers.

GITHUB_APP_NAME

The name of the GitHub OAuth App.

GITHUB_CLIENT_ID

The Client ID from the GitHub OAuth App.

Secrets

Secrets are managed in .dev.vars for local development.

From packages/codius-astro:

cp .example.dev.vars .dev.vars

Add the secrets from your .dev.vars to your Cloudflare Pages project as encrypted secrets.

CLOUDFLARE_ACCOUNT_ID

Your Cloudflare Account ID.

CLOUDFLARE_API_TOKEN

Your Cloudflare API Token.

GITHUB_CLIENT_SECRET

The Client Secret from the GitHub OAuth App.

GITHUB_ACCESS_TOKEN

The GitHub Access Token for deploying workers.

GITHUB_WEBHOOK_SECRET

The secret for the GitHub repository webhook.

STRIPE_SECRET_KEY

Your Stripe Secret Key.

STRIPE_TOPUP_PRICE_ID

The Stripe Price ID for topping up your account.

🚀 Deploy

You can deploy the codius-astro site to Cloudflare Pages via either direct upload or git integration.

For direct upload, you can use the following command from the monorepo root:

pnpm --filter codius-astro pages deploy

🧞 Commands

All commands are run from the root of the monorepo, from a terminal:

Command Action
pnpm install Installs dependencies
pnpm --filter codius-astro run dev Starts local dev server at localhost:8788
pnpm --filter codius-astro run build Build your production site to ./dist/
pnpm --filter codius-astro run preview Preview your build locally, before deploying
pnpm --filter codius-astro run astro ... Run CLI commands like astro add, astro check
pnpm --filter codius-astro run astro -- --help Get help using the Astro CLI
pnpm --filter codius-astro run smee Start a local webhook proxy with Smee.io

Footnotes

  1. Cloudflare wrangler cli currently doesn't support local development for Workers for Platforms. See https://github.com/cloudflare/workers-sdk/pull/5622