如何从 Next.js 中间件返回 HTML?

Ali*_*EXE 2 html javascript next.js

我正在尝试返回 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>
Run Code Online (Sandbox Code Playgroud)

是否可以?因为我在NextResponse对象上找不到方法。

如何从中间件返回 HTML?

Jon*_*ben 5

不再支持此功能。

从 v12.2+ 开始,中间件不再能够生成响应主体。

https://nextjs.org/docs/messages/returning-response-body-in-middleware