@nuxt/docs-nightly 5.0.0-29846154.7802b2c2 → 5.0.0-29850714.87a4b2c4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -462,12 +462,13 @@ export default useBase('/api/hello', router.handler)
|
|
|
462
462
|
This is an experimental feature and is available in all environments.
|
|
463
463
|
::
|
|
464
464
|
|
|
465
|
+
You can return streams directly from the event handler.
|
|
466
|
+
|
|
465
467
|
```ts [server/api/foo.get.ts]
|
|
466
468
|
import fs from 'node:fs'
|
|
467
|
-
import { sendStream } from 'h3'
|
|
468
469
|
|
|
469
|
-
export default defineEventHandler((
|
|
470
|
-
return
|
|
470
|
+
export default defineEventHandler(() => {
|
|
471
|
+
return fs.createReadStream('/path/to/file')
|
|
471
472
|
})
|
|
472
473
|
```
|
|
473
474
|
|
|
@@ -124,9 +124,38 @@ export default defineNuxtModule({
|
|
|
124
124
|
})
|
|
125
125
|
```
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
### Other Variants
|
|
128
|
+
|
|
129
|
+
For anything else that points at server code, such as an alias, a type template or an app plugin that reads the server event, you can use `resolveServerVariant` to resolve the variant that is appropriate for this version of Nuxt, or `undefined` if it runs none of them.
|
|
130
|
+
|
|
131
|
+
`addServerImports` accepts the same variants in `from`.
|
|
132
|
+
|
|
133
|
+
```ts [module.ts]
|
|
134
|
+
import { addServerImports, createResolver, defineNuxtModule, resolveServerVariant } from '@nuxt/kit'
|
|
135
|
+
|
|
136
|
+
export default defineNuxtModule({
|
|
137
|
+
meta: { name: 'my-module' },
|
|
138
|
+
setup (_options, nuxt) {
|
|
139
|
+
const { resolve } = createResolver(import.meta.url)
|
|
140
|
+
|
|
141
|
+
const someServerFile = resolveServerVariant({
|
|
142
|
+
nuxt: resolve('./runtime/server'),
|
|
143
|
+
nitro2: resolve('./runtime/server.legacy'),
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
if (someServerFile) {
|
|
147
|
+
nuxt.options.alias['#my-module/server'] = someServerFile
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
addServerImports({
|
|
151
|
+
name: 'verifyToken',
|
|
152
|
+
from: { nuxt: resolve('./runtime/verify'), nitro2: resolve('./runtime/verify.legacy') },
|
|
153
|
+
})
|
|
154
|
+
},
|
|
155
|
+
})
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
If running with `nitropack` v2, `nitro2` will always be preferred over `nuxt`, and if running with `nitro` v3, `nitro3` will always be preferred over `nuxt`. So, if you need to test the `nuxt` variant, set `server.builder` in your test fixture to a builder that is not Nitro, such as `@nuxt/vite-server`.
|
|
130
159
|
|
|
131
160
|
### Declaring What You Cannot Infer
|
|
132
161
|
|