This commit is contained in:
parent
f326ecc072
commit
1f3d7b9a9c
|
|
@ -1,15 +1,26 @@
|
||||||
import { NextResponse } from 'next/server'
|
import { NextResponse } from 'next/server'
|
||||||
import { getRuntimeEnv } from '@/lib/ipconfig' // 路径按你项目实际调整
|
import { getRuntimeEnv } from '@/lib/ipconfig'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
|
|
||||||
export const runtime = 'nodejs'
|
export const runtime = 'nodejs'
|
||||||
|
|
||||||
|
// ✅ 重定向 console.log / console.error 到文件
|
||||||
|
const logStream = fs.createWriteStream('/tmp/health-api.log', { flags: 'a' });
|
||||||
|
|
||||||
|
console.log = (...args: any[]) => {
|
||||||
|
logStream.write(`[log ${new Date().toISOString()}] ${args.join(' ')}\n`);
|
||||||
|
};
|
||||||
|
|
||||||
|
console.error = (...args: any[]) => {
|
||||||
|
logStream.write(`[error ${new Date().toISOString()}] ${args.join(' ')}\n`);
|
||||||
|
};
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
let ip: string | null = null
|
let ip: string | null = null
|
||||||
let res: string | undefined = undefined
|
let res: string | undefined = undefined
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.appendFileSync('/tmp/health-api.log', `[${new Date().toISOString()}] API HIT\n`);
|
console.log('✅ [health-check] API HIT');
|
||||||
res = await getRuntimeEnv('SUPABASE_URL')
|
res = await getRuntimeEnv('SUPABASE_URL')
|
||||||
ip = res ?? null
|
ip = res ?? null
|
||||||
|
|
||||||
|
|
@ -20,7 +31,6 @@ export async function GET() {
|
||||||
console.error('[health-check] 捕获异常:', e)
|
console.error('[health-check] 捕获异常:', e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 额外打印进程环境变量(一次就行,便于调试)
|
|
||||||
console.log('[health-check] process.env.SUPABASE_URL =', process.env.SUPABASE_URL)
|
console.log('[health-check] process.env.SUPABASE_URL =', process.env.SUPABASE_URL)
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue