Export `nitroApp` instance
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 899
- Avg merge
- 2d 24m
- Merged PRs (30d)
- 40
Description
Describe the feature
Context: #3578 (@markthree)
I am currently developing a
zero-downtimeAPI service based on H3 and several Nitro applications. I've found that exporting NitroApps might be more user-friendly, as users may need to access their internal options or perform certain actions (such as invoking shutdown hooks).Example
// plugins/db.ts
// ignore some codes
export default defineNitroPlugin((nitro) => {
nitro.hooks.hook("close", async () => {
const db = await useDB();
db.close();
});
})
// user case
import("./.output/server/index.mjs").then(({ nitroApp }) => {
// ignore some codes
nitroApp.hooks.callHook("close");
})
Additional information
- Would you be willing to help implement this feature?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the generated server entry point .output/server/index.mjs and trace how the Nitro application instance is created and exported. Verify that importing the entry point exposes nitroApp and that its hooks can be invoked as shown; the feature is complete when this public export works for generated Nitro applications.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100