Created
March 18, 2025 21:26
-
-
Save programmarchy/02f480063befcba4a88cbe406a47a917 to your computer and use it in GitHub Desktop.
SuperJSON middleware for Hono
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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