Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stevedylandev/4aa1fc569bcba46b7169193c0498d0b3 to your computer and use it in GitHub Desktop.
Save stevedylandev/4aa1fc569bcba46b7169193c0498d0b3 to your computer and use it in GitHub Desktop.
How you can easily deploy an existing Hono app to a Cloudflare Worker

Introduction

This guide is for those who might be using bhvr and want to deploy their Hono server to a Cloudflare worker. While it's relatively simple to setup I will be looking into how to automate it into the CLI setup.

Setup

  1. Install type dependencies to the server repo and update the server/tsconfig.json file.
bun add @cloudflare/workers-types
{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "types": ["bun-types", "@cloudflare/workers-types"],
    // rest of the config...
}
  1. Add a new file called wrangler.json to the root of your server directory and put in the following contents
{
  "name": "bhvr-server",
  "main": "src/index.ts",
  "compatibility_date": "2025-02-13",
  "compatibility_flags": [
    "nodejs_compat"
  ]
}
  1. Login to Your Cloudflare account with the Wrangler CLI
bunx wrangler login
  1. Deploy
bunx wrangler deploy --minify

Optional: Create a new script in package.json to automate deployments

  "scripts": {
    "dev": "bun run --hot src/index.ts",
    "deploy": "wrangler deploy --minify"
  },

Questions

Feel free to contact me if you have any questions or concerns!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment