增加ip 的白名單
總共7個IP地址,分佈在4個地點: 岡山:1個IP 汐止:2個IP 新竹:2個IP 璟茂:2個IP
This commit is contained in:
29
app/api/ip/route.ts
Normal file
29
app/api/ip/route.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { getClientIp, isIpAllowed } from '@/lib/ip-utils'
|
||||
|
||||
// 強制動態渲染
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const clientIp = getClientIp(request)
|
||||
const allowedIps = process.env.ALLOWED_IPS || ''
|
||||
const enableIpWhitelist = process.env.ENABLE_IP_WHITELIST === 'true'
|
||||
|
||||
const isAllowed = enableIpWhitelist ? isIpAllowed(clientIp, allowedIps) : true
|
||||
|
||||
return NextResponse.json({
|
||||
ip: clientIp,
|
||||
isAllowed,
|
||||
enableIpWhitelist,
|
||||
allowedIps: enableIpWhitelist ? allowedIps.split(',').map(ip => ip.trim()) : [],
|
||||
timestamp: new Date().toISOString()
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error getting IP info:', error)
|
||||
return NextResponse.json(
|
||||
{ error: '無法獲取IP信息' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user