# Migrate a Val Town HTTP endpoint to Gregale with Bun and Hono

Gregale · Updated 2026-11-30

Move a stateless HTTP val to Bun and Hono, compare real HTTP responses, and point callers directly at the new URL.

A public HTTP val can move to a Bun web service on Gregale without changing its routes. Keep the Hono handlers, replace Deno-specific imports with package dependencies, and have Bun listen on the app port. Compare the old and new responses before you update any callers or redirects.

[Get the runnable example on GitHub](https://github.com/gregale-dev/val-town-hono-migration).

Val Town [makes code and redirect settings read-only on December 10, 2026](https://docs.val.town/migration/redirects) and [ends hosting on January 10, 2027](https://blog.val.town/winding-down). This guide covers **stateless HTTP only**. SQLite, blobs, email handlers, cron, Val Town access control, and platform-specific imports need their own migration. Do not make a formerly private val public to follow this example.

## Quick start

1. Save your val and capture a successful request and a missing route from the old URL **before** changing any redirect.
2. Run the Bun/Hono example locally, then [deploy it as a separate HTTP app](#3-deploy-to-gregale). The sample needs no database or secrets. We tested it on a Scale account; the exact Dockerfile path has not been verified on a fresh Free account.
3. [Compare the old and new responses](#4-verify-the-public-application-route-then-switch-callers) and update a test caller to the new URL. Keep private endpoints private.

### What we verified

For the synthetic sample, a local Deno version of the Val Town handler and the local Bun version gave the same results:

| Request            | Local Deno and Bun result            |
| ------------------ | ------------------------------------ |
| `GET /greet/world` | `200`, `{"message":"Hello, world!"}` |
| `GET /not-found`   | `404`, `404 Not Found`               |

We also observed both results on the deployed Gregale sample. We did not run the comparison against a hosted Val Town URL or change a live redirect. Use your own old URL for the migration check.

## 1. Save the code and capture the current behavior

Export the val before the freeze. If you use Git, [Val Town explains how to store the source on GitHub](https://docs.val.town/migration). Capture one successful request and one miss against your current URL before configuring a redirect:

```sh
OLD_URL='https://yourname-api.web.val.run'
curl -sS -i "$OLD_URL/greet/world"
curl -sS -i "$OLD_URL/not-found"
```

Save the status, content type, and body. If your app receives POSTs, also save a synthetic request and verify its side effect once in an isolated test environment.

## 2. Run the same route with Bun

Create a new folder. Save this as `package.json`:

```json
{
  "name": "val-town-hono-migration",
  "private": true,
  "type": "module",
  "scripts": { "start": "bun run index.ts" },
  "dependencies": { "hono": "4.13.23" }
}
```

The [Val Town Hono example](https://docs.val.town/guides/deploy-an-api-endpoint) exports `app.fetch` for Val Town to call. In Bun, keep the route and export the server options as shown in the [Hono Bun guide](https://hono.dev/docs/getting-started/bun). Save as `index.ts`:

```ts
import { Hono } from 'hono';

const app = new Hono();
app.get('/greet/:name', (c) => c.json({ message: `Hello, ${c.req.param('name')}!` }));
app.get('/healthz', (c) => c.text('ok'));

export default {
  hostname: '0.0.0.0',
  port: Number(process.env.PORT ?? 8080),
  fetch: app.fetch,
};
```

With Bun 1.4.5 installed, generate `bun.lock`, then commit it with the source. Run the service in one terminal:

```sh
bun install
bun run start
```

From another terminal, `curl -i http://127.0.0.1:8080/greet/world` should return HTTP 200 with `{"message":"Hello, world!"}`. A request to `/not-found` should return HTTP 404. If you have a custom val, also test its actual headers, error bodies, and request methods; a matching example does not guarantee your own route behaves identically.

## 3. Deploy to Gregale

Create `gregale.yaml`. The example is intentionally public and has no database or secrets.

```yaml
hosting:
  port: 8080
  health: /healthz
```

Add a `Dockerfile` to pin the Bun version used in the build:

```dockerfile
FROM oven/bun:1.4.5-alpine
WORKDIR /app
COPY package.json bun.lock ./
RUN bun install --frozen-lockfile --production
COPY index.ts ./
ENV PORT=8080
EXPOSE 8080
CMD ["bun", "run", "index.ts"]
```

Save a `.dockerignore` with `node_modules`, `.env*`, and `.git`, each on a separate line. Never copy credentials into the bundle. If your migrated app needs third-party tokens, supply fresh server-side secrets through the platform and leave them out of shell history, source, and logs.

Follow [Gregale’s CLI quickstart](https://gregale.dev/docs/quickstart) to install and authenticate. From this folder, pick a new app name and deploy the local source:

```sh
gregale deploy --name my-val-town-api
gregale app update my-val-town-api --visibility public --public-auth open --no-require-authn
```

This example is intentionally public. Keep previously private routes private, and configure the access policy they need instead.

Use the HTTPS URL printed by the CLI for the next step. If the CLI reports an accepted deployment still in progress, check that deployment rather than resubmitting. For build errors, check the [Dockerfile build documentation](https://gregale.dev/docs/deploy-from-github#dockerfile-builds). For account and resource limits, check [Gregale pricing](https://gregale.dev/pricing) before moving traffic.

## 4. Verify the public application route, then switch callers

Set `NEW_URL` to the actual HTTPS URL, without a trailing slash. Do not forward your Gregale account key to the public application route.

```sh
NEW_URL='https://my-val-town-api.gregale.app'
curl -sS -i "$NEW_URL/greet/world"
curl -sS -i "$NEW_URL/not-found"
```

For this example, look for HTTP 200 and the greeting JSON, then HTTP 404 and `404 Not Found`. Compare these with the old endpoint, not just a deployment status or a `/healthz` response. For browser clients, try a request from the real frontend origin against the direct new URL. If it is cross-origin, allow only the intended origins and retest browser preflight where applicable.

Change webhook destinations at the provider and send a synthetic event, since some senders do not follow redirects. Once direct clients work, use Val Town’s redirect feature only if existing links also need it. A redirect immediately stops requests from reaching the old val; it becomes permanent on the December 10 freeze. For an owned domain, follow the new host’s domain verification instructions and test HTTPS before changing live callers.

## Frequently asked questions

**Can I keep my paths?** Yes, if the Bun app registers the same routes and the caller uses the new host. Check both one valid path and one error case.

**Does this migrate SQLite and cron jobs?** No. Export those separately, choose replacement services, and verify each workflow. Instance disk is not a durable replacement for Val Town SQLite.

**Is this a free deployment?** The example needs one web app and no managed database. Check the current plan limits and your app’s measured resource needs. A test on a paid account does not establish the Free onboarding path.

## Questions

### Can I migrate Val Town SQLite with this guide?

No. This guide is limited to a public, stateless HTTP endpoint. SQLite, blobs, email and cron have separate migration requirements.

### Can callers just follow the old URL?

Update webhook callers directly when possible. Not all webhook senders follow redirects.

Canonical URL: https://gregale.dev/articles/migrate-val-town-http-to-gregale

