Skip to content

Commit f921892

Browse files
committed
chore: use middleware instead of plugin
1 parent 6c73e6d commit f921892

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/module.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,12 @@ export default defineNuxtModule<ModuleOptions>({
166166
nuxt.options.nitro.commands.preview = 'npx nuxthub preview'
167167
nuxt.options.nitro.commands.deploy = 'npx nuxthub deploy'
168168

169-
// Add the env plugin
170-
addServerPlugin(resolve('./runtime/env'))
169+
// Add the env middleware
170+
nuxt.options.nitro.handlers ||= []
171+
nuxt.options.nitro.handlers.unshift({
172+
middleware: true,
173+
handler: resolve('./runtime/env')
174+
})
171175
}
172176

173177
// Local development without remote connection

src/runtime/env.ts

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import type { NitroAppPlugin } from 'nitropack'
2-
import type { H3Event } from 'h3'
1+
import { eventHandler } from 'h3'
32

43
// Hack around Cloudflare regression since nodejs_compat_v2 for process.env
5-
export default <NitroAppPlugin> function (nitroApp) {
6-
nitroApp.hooks.hook('request', async (event: H3Event) => {
7-
const env = event.context.cloudflare?.env || {}
8-
for (const key in env) {
9-
process.env[key] = env[key]
10-
}
11-
})
12-
}
4+
export default eventHandler((event) => {
5+
const env = event.context.cloudflare?.env || {}
6+
for (const key in env) {
7+
process.env[key] = env[key]
8+
}
9+
})

0 commit comments

Comments
 (0)