Skip to content

Instantly share code, notes, and snippets.

@programmarchy
Created March 18, 2025 21:26
Show Gist options
  • Save programmarchy/02f480063befcba4a88cbe406a47a917 to your computer and use it in GitHub Desktop.
Save programmarchy/02f480063befcba4a88cbe406a47a917 to your computer and use it in GitHub Desktop.
SuperJSON middleware for Hono
import type { MiddlewareHandler } from "hono"
import superjson from "superjson"
export const superjsonMiddleware = (): MiddlewareHandler => {
return async (c, next) => {
if (c.req.header("x-superjson") === "true") {
const json = c.json.bind(c)
c.json = (object: any, ...args: any[]) => {
return json(superjson.serialize(object), ...args)
}
}
return next()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment