Hono on Vercel
Hono is a fast and lightweight web application framework built on Web Standards. You can deploy a Hono app to Vercel with zero configuration.
Start with Hono on Vercel by using the following Hono template to deploy to Vercel with zero configuration:
Vercel deployments can integrate with your git provider to generate preview URLs for each pull request you make to your Hono project.
To run a Hono application on Vercel, ensure that the default export of index.ts
or src/index.ts
is the Hono application router.
import { Hono } from 'hono';
const app = new Hono();
// ...
export default app;
To run your Hono application locally, use Vercel CLI:
vc dev
This ensures that the application will use the default export to run the same as when deployed to Vercel. The application will be available on your localhost
.
Hono has the concept of "Middleware" as a part of the framework. This is different from Vercel Routing Middleware, though they can be used together.
In Hono, Middleware runs before a request handler in the framework's router. This is commonly used for loggers, CORS handling, or authentication. The code in the Hono application might look like this:
app.use(logger());
app.use('/posts/*', cors());
app.post('/posts/*', basicAuth());
More examples of Hono Middleware can be found in the Hono documentation.
In Vercel, Routing Middleware executes code before a request is processed by the application. This gives you a way to handle rewrites, redirects, headers, and more, before returning a response. See the Routing Middleware documentation for examples.
When you deploy a Hono app to Vercel, your server routes automatically become Vercel Functions and use Fluid compute by default.
Vercel Functions support streaming which can be used with Hono's stream()
function.
app.get('/stream', (c) => {
return stream(c, async (stream) => {
// Write a process to be executed when aborted.
stream.onAbort(() => {
console.log('Aborted!');
});
// Write a Uint8Array.
await stream.write(new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f]));
// Pipe a readable stream.
await stream.pipe(anotherReadableStream);
});
});
Learn more about deploying Hono projects on Vercel with the following resources:
Was this helpful?