import { NextResponse } from 'next/server'
const RETRY_AFTER_SECONDS = '600'
const MAINTENANCE_HTML = `
Under maintenance
We'll be back shortly
Morphic is undergoing scheduled maintenance. Your chats are safe. Please check back in a few minutes.
`
export function isMaintenanceMode(): boolean {
return process.env.MAINTENANCE_MODE === 'true'
}
// API callers get JSON so clients can show their own error state
export function maintenanceResponse(pathname: string): NextResponse {
const headers = {
'Retry-After': RETRY_AFTER_SECONDS,
'Cache-Control': 'no-store'
}
if (pathname.startsWith('/api/')) {
return NextResponse.json(
{ error: 'Service under maintenance' },
{ status: 503, headers }
)
}
return new NextResponse(MAINTENANCE_HTML, {
status: 503,
headers: { ...headers, 'Content-Type': 'text/html; charset=utf-8' }
})
}