@nuxt/docs-nightly 4.3.0-29431381.f1713850 → 4.3.0-29431658.1c44667d
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.
|
@@ -130,6 +130,24 @@ export const defineWrappedResponseHandler = <T extends EventHandlerRequest, D> (
|
|
|
130
130
|
})
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
+
## Server Alias
|
|
134
|
+
|
|
135
|
+
You can use the `#server` alias to import files from anywhere within the `server/` directory, regardless of the importing file's location.
|
|
136
|
+
|
|
137
|
+
```ts [server/api/users/[id]/profile.ts]
|
|
138
|
+
// Instead of relative paths like this:
|
|
139
|
+
// import { formatUser } from '../../../utils/formatUser'
|
|
140
|
+
|
|
141
|
+
// Use the #server alias:
|
|
142
|
+
import { formatUser } from '#server/utils/formatUser'
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
This alias ensures consistent imports across your server code, especially useful in deeply nested route handlers.
|
|
146
|
+
|
|
147
|
+
::note
|
|
148
|
+
The `#server` alias can only be used within the `server/` directory. Importing from `#server` in client code will result in an error.
|
|
149
|
+
::
|
|
150
|
+
|
|
133
151
|
## Server Types
|
|
134
152
|
|
|
135
153
|
Auto-imports and other types are different for the `server/` directory, as it is running in a different context from the `app/` directory.
|