diff --git a/src/app.ts b/src/app.ts index 636d4b2a..4d827a6e 100644 --- a/src/app.ts +++ b/src/app.ts @@ -231,5 +231,10 @@ function handleHandlerResponse(event: H3Event, val: any, jsonSpace?: number) { return send(event, JSON.stringify(val, undefined, jsonSpace), MIMES.json); } + // BigInt + if (valType === "bigint") { + return send(event, val.toString(), MIMES.json); + } + return false; } diff --git a/test/app.test.ts b/test/app.test.ts index 38709293..880c09db 100644 --- a/test/app.test.ts +++ b/test/app.test.ts @@ -15,7 +15,7 @@ describe("app", () => { let request: SuperTest; beforeEach(() => { - app = createApp({ debug: false }); + app = createApp({ debug: true }); request = supertest(toNodeListener(app)); }); @@ -29,6 +29,16 @@ describe("app", () => { expect(res.body).toEqual({ url: "/" }); }); + it("can return bigint directly", async () => { + app.use( + "/", + eventHandler(() => BigInt(9_007_199_254_740_991)) + ); + const res = await request.get("/"); + + expect(res.text).toBe("9007199254740991"); + }); + it("can return Response directly", async () => { app.use( "/",