Skip to content

Commit

Permalink
feat: type nitro app runtime hooks (#1316)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Jun 18, 2023
1 parent 88b4e11 commit 3c446ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/runtime/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
createFetch as createLocalFetch,
} from "unenv/runtime/fetch/index";
import { createHooks, Hookable } from "hookable";
import { NitroRuntimeHooks } from "../types";
import { useRuntimeConfig } from "./config";
import { cachedEventHandler } from "./cache";
import { createRouteRulesHandler, getRouteRulesForPath } from "./route-rules";
Expand All @@ -26,16 +27,15 @@ import { handlers } from "#internal/nitro/virtual/server-handlers";
export interface NitroApp {
h3App: H3App;
router: Router;
// TODO: Type hooks and allow extending
hooks: Hookable;
hooks: Hookable<NitroRuntimeHooks>;
localCall: ReturnType<typeof createCall>;
localFetch: ReturnType<typeof createLocalFetch>;
}

function createNitroApp(): NitroApp {
const config = useRuntimeConfig();

const hooks = createHooks();
const hooks = createHooks<NitroRuntimeHooks>();

const h3App = createApp({
debug: destr(process.env.DEBUG),
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type { H3Event } from "h3";

import type { RenderResponse } from "../types";
export type { NitroApp } from "./app";
export type {
CacheEntry,
Expand All @@ -16,3 +19,11 @@ declare module "h3" {
$fetch: typeof globalThis.fetch;
}
}

export interface NitroRuntimeHooks {
"render:response": (
response: Partial<RenderResponse>,
context: { event: H3Event }
) => void;
close: () => void;
}

0 comments on commit 3c446ad

Please sign in to comment.