我尝试返回HTTP状态代码410(消失)以及一个自定义的简单HTML:
<h1>Error 410</h1> <h2>Permanently deleted or Gone</h2> <p>This page is not found and is gone from this server forever</p>
可能吗?因为我找不到NextResponse对象的方法。如何从中间件返回HTML?
jgwigjjp1#
不再支持此功能。从v12.2+开始,中间件不再生成响应主体。https://nextjs.org/docs/messages/returning-response-body-in-middleware
sgtfey8w2#
这是类型.没有方法发送html
type NextApiResponse<T = any> = ServerResponse<IncomingMessage> & { send: Send<T>; json: Send<T>; status: (statusCode: number) => NextApiResponse<T>; redirect(url: string): NextApiResponse<T>; redirect(status: number, url: string): NextApiResponse<T>; setPreviewData: (data: object | string, options?: { maxAge?: number; path?: string; }) => NextApiResponse<T>; clearPreviewData: (options?: { path?: string; }) => NextApiResponse<T>; unstable_revalidate: () => void; revalidate: (urlPath: string, opts?: { unstable_onlyGenerated?: boolean; }) => Promise<void>; }
express具有sendFile
express
sendFile
app.get("/", (req, res) => { res.sendFile(__dirname + "/index.html"); });
发送
res.json(body) - Sends a JSON response. body must be a serializable object res.send(body) - Sends the HTTP response. body can be a string, an object or a Buffer
您可以将用户重定向到显示html的URL
2条答案
按热度按时间jgwigjjp1#
不再支持此功能。
从v12.2+开始,中间件不再生成响应主体。
https://nextjs.org/docs/messages/returning-response-body-in-middleware
sgtfey8w2#
这是类型.没有方法发送html
express
具有sendFile
发送
您可以将用户重定向到显示html的URL