-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(hooks): enabled use of useAppConfig() and useRuntimeConfig() with…
…in request hooks If the nitro context isn't already initialized, it will be initialized, rather than error.
- Loading branch information
Showing
7 changed files
with
163 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
process.env.NITRO_DYNAMIC = "from-env"; | ||
|
||
export default eventHandler((event) => { | ||
const appConfig = useAppConfig(event); | ||
appConfig.dynamic = "from-middleware"; | ||
if (event.path.startsWith("/config")) { | ||
const appConfig = useAppConfig(event); | ||
appConfig.dynamic = "from-middleware"; | ||
} | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export default defineNitroPlugin((app) => { | ||
app.hooks.hook("request", (event) => { | ||
if (event.path.startsWith("/hooks")) { | ||
const qs = getQuery(event); | ||
switch (qs.change) { | ||
case "useAppConfig": { | ||
useAppConfig(event).dynamic = "from-hook"; | ||
break; | ||
} | ||
case "useRuntimeConfig": { | ||
useRuntimeConfig(event).dynamic = "from-hook"; | ||
break; | ||
} | ||
} | ||
} | ||
}); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const sharedAppConfig = useAppConfig(); | ||
const sharedRuntimeConfig = useRuntimeConfig(); | ||
|
||
export default eventHandler((event) => { | ||
const appConfig = useAppConfig(event); | ||
const runtimeConfig = useRuntimeConfig(event); | ||
|
||
return { | ||
sharedAppConfig, | ||
appConfig, | ||
runtimeConfig, | ||
sharedRuntimeConfig, | ||
}; | ||
}); |
This file contains 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