mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
Continuation of https://github.com/vercel/next.js/pull/78166 this implements the handler interface for app router pages, This does not move the response handling inside of the handler yet as that will be in a follow-up PR to keep the changes isolated. This still returns the RenderResult for the base-server to continue to handle. Validated against deploy tests https://github.com/vercel/vercel/pull/13389 and https://github.com/vercel/next.js/actions/runs/15358616431/job/43222466204
31 lines
848 B
JavaScript
31 lines
848 B
JavaScript
import fs from 'fs'
|
|
import path from 'path'
|
|
|
|
const dir = path.dirname(new URL(import.meta.url).pathname)
|
|
const logPath = path.join(dir, 'output-log.json')
|
|
|
|
export async function register() {
|
|
fs.writeFileSync(logPath, '{}', 'utf8')
|
|
}
|
|
|
|
// Since only Node.js runtime support ISR, we can just write the error state to a file here.
|
|
// `onRequestError` will only be bundled within the Node.js runtime.
|
|
export async function onRequestError(err, request, context) {
|
|
const payload = {
|
|
message: err.message,
|
|
request,
|
|
context,
|
|
}
|
|
|
|
const json = fs.existsSync(logPath)
|
|
? JSON.parse(fs.readFileSync(logPath, 'utf8'))
|
|
: {}
|
|
|
|
json[payload.message] = payload
|
|
|
|
console.log(
|
|
`[instrumentation] write-log:${payload.message} ${payload.context.revalidateReason}`
|
|
)
|
|
fs.writeFileSync(logPath, JSON.stringify(json, null, 2), 'utf8')
|
|
}
|