Wrangler

Deploy Serverless API Gateway to Cloudflare Workers using Wrangler CLI. Steps for local dev, environment configs, and production deployment.

Wrangler is the official Cloudflare CLI for building and deploying Workers. The Serverless API Gateway uses Wrangler to push your gateway configuration and worker code to Cloudflare's edge network.

Prerequisites

  1. Install Wrangler globally or as a project dependency:

npm install -g wrangler
  1. Authenticate with your Cloudflare account:

wrangler login
  1. Ensure your API configuration (src/api-config.json) and wrangler.toml are set up correctly.

Deploying

Deploy the gateway to Cloudflare Workers with a single command:

wrangler deploy

This reads your wrangler.toml, bundles the worker code along with your API configuration, and publishes it to Cloudflare's global network.

Environment-Specific Deploys

Use separate configuration files for different environments (staging, production, auth-specific):

wrangler deploy --config wrangler.toml
wrangler deploy --config wrangler.auth.toml

Keep sensitive configuration files like wrangler.auth.toml out of version control by adding them to .gitignore.

Local Development

Test your gateway locally before deploying:

This starts a local development server that simulates the Cloudflare Workers runtime, allowing you to test routing, CORS, and authorization without deploying.

Setting Secrets

Store sensitive values like JWT secrets or API keys as encrypted Wrangler secrets rather than placing them in configuration files:

See Also

  • Configuration Guide -- set up routing, CORS, authorizer, and server definitions before deploying.

  • GitHub Actions -- automate deployments with CI/CD instead of manual Wrangler commands.

  • Getting Started -- clone the repository and install dependencies before your first deploy.

Last updated