# Wrangler

[Wrangler](https://developers.cloudflare.com/workers/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:

```bash
npm install -g wrangler
```

2. Authenticate with your Cloudflare account:

```bash
wrangler login
```

3. Ensure your [API configuration](/configuration/overview.md) (`src/api-config.json`) and `wrangler.toml` are set up correctly.

### Deploying

Deploy the gateway to Cloudflare Workers with a single command:

```bash
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):

```bash
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:

```bash
wrangler dev
```

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:

```bash
wrangler secret put JWT_SECRET
```

### See Also

* [Configuration Guide](/configuration/overview.md) -- set up routing, CORS, authorizer, and server definitions before deploying.
* [GitHub Actions](/deployment/github-actions.md) -- automate deployments with CI/CD instead of manual Wrangler commands.
* [Getting Started](/getting-started/introduction.md) -- clone the repository and install dependencies before your first deploy.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.serverlessapigateway.com/deployment/wrangler.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
