Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

@lowerdeck/hono

Create Hono web applications with Metorial defaults. Includes error handling for ServiceError, 404 handling, and CORS configuration.

Installation

npm install @lowerdeck/hono
yarn add @lowerdeck/hono
bun add @lowerdeck/hono
pnpm add @lowerdeck/hono

Usage

import { createHono, cors } from '@lowerdeck/hono';

// Create Hono app with defaults
const app = createHono('/api');

// Routes
app.get('/users/:id', async (c) => {
  const id = c.req.param('id');
  const user = await getUser(id);
  return c.json(user);
});

// ServiceError handling is automatic
import { createError } from '@lowerdeck/error';

const UserNotFound = createError({
  statusCode: 404,
  errorCode: 'USER_NOT_FOUND',
  message: 'User not found'
});

app.get('/users/:id', async (c) => {
  const user = await getUser(id);
  if (!user) {
    throw UserNotFound(); // Automatically handled
  }
  return c.json(user);
});

// Custom CORS configuration
app.use('/api/*', cors({
  origin: 'https://example.com',
  credentials: true
}));

export default app;

License

This project is licensed under the Apache License 2.0.

Built with ❤️ by Metorial