mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
This PR removes middleware docs and adds a "Migration to Proxy" section to the Proxy docs, which explains the rationale for the renaming to Proxy and provides a migration guide. Did not remove `middleware-upgrade-docs` as it's an upgrade doc from the legacy middleware. Below are untouched as they need codebase changes: - `instrumentation` docs - `onRequestError` has `context.routeType` as `'middleware'` - `adapterPath` docs - has `MiddlewareMatcher` type example - `ProxyConfig` - has a user-facing `MiddlewareMatcher` type --------- Co-authored-by: Joseph Chamochumbi <[email protected]>
26 lines
590 B
Plaintext
26 lines
590 B
Plaintext
---
|
|
title: No Server Import In Page
|
|
---
|
|
|
|
> Prevent usage of `next/server` outside of `proxy.js`.
|
|
|
|
## Why This Error Occurred
|
|
|
|
`next/server` was imported outside of `proxy.{js,ts}`.
|
|
|
|
## Possible Ways to Fix It
|
|
|
|
Only import and use `next/server` in a file located within the project root directory: `proxy.{js,ts}`.
|
|
|
|
```ts filename="proxy.ts"
|
|
import type { NextFetchEvent, NextRequest } from 'next/server'
|
|
|
|
export function proxy(req: NextRequest, ev: NextFetchEvent) {
|
|
return new Response('Hello, world!')
|
|
}
|
|
```
|
|
|
|
## Useful Links
|
|
|
|
- [Proxy](/docs/pages/api-reference/file-conventions/proxy)
|