← back to Dear Bubbe Nextjs

app/api/health-logs/route.ts

28 lines

import { NextRequest, NextResponse } from 'next/server'
import { readFile } from 'fs/promises'
import { existsSync } from 'fs'

export async function GET(request: NextRequest) {
  try {
    const logFile = '/root/Projects/dear-bubbe-nextjs/health-monitor.log'
    
    if (!existsSync(logFile)) {
      return NextResponse.json({ error: 'Log file not found' }, { status: 404 })
    }
    
    const logs = await readFile(logFile, 'utf-8')
    
    // Return last 100 lines for dashboard
    const lines = logs.split('\n').slice(-100).join('\n')
    
    return new NextResponse(lines, {
      headers: {
        'Content-Type': 'text/plain',
        'Cache-Control': 'no-cache, no-store, must-revalidate'
      }
    })
  } catch (error) {
    console.error('Error reading health logs:', error)
    return NextResponse.json({ error: 'Failed to read logs' }, { status: 500 })
  }
}