mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
docs: added addServerHandler
example to modules author guide (#22603)
This commit is contained in:
parent
9fcd99eccc
commit
2a4867a23f
@ -375,6 +375,40 @@ export default defineNuxtModule({
|
||||
})
|
||||
```
|
||||
|
||||
#### Injecting Server Routes With `addServerHandler`
|
||||
|
||||
```ts
|
||||
import { defineNuxtModule, addServerHandler, createResolver } from '@nuxt/kit'
|
||||
|
||||
export default defineNuxtModule({
|
||||
setup(options, nuxt) {
|
||||
const resolver = createResolver(import.meta.url)
|
||||
|
||||
addServerHandler({
|
||||
route: '/api/hello',
|
||||
handler: resolver.resolve('./runtime/server/api/hello/index.get.ts')
|
||||
})
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
You can also add a dynamic server route:
|
||||
|
||||
```ts
|
||||
import { defineNuxtModule, addServerHandler, createResolver } from '@nuxt/kit'
|
||||
|
||||
export default defineNuxtModule({
|
||||
setup(options, nuxt) {
|
||||
const resolver = createResolver(import.meta.url)
|
||||
|
||||
addServerHandler({
|
||||
route: '/api/hello/:name',
|
||||
handler: resolver.resolve('./runtime/server/api/hello/[name].get.ts')
|
||||
})
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
#### Injecting Other Assets
|
||||
|
||||
If your module should provide other kinds of assets, they can also be injected. Here's a simple example module injecting a stylesheet through Nuxt's `css` array.
|
||||
|
Loading…
Reference in New Issue
Block a user