File tree Expand file tree Collapse file tree 4 files changed +113
-18
lines changed
prisma/migrations/20250606111858_add_last_event_time_to_tunnel Expand file tree Collapse file tree 4 files changed +113
-18
lines changed Original file line number Diff line number Diff line change 1+ import { NextRequest , NextResponse } from 'next/server' ;
2+ import { logger } from '@/lib/logger' ;
3+ import { fetchWithSSLSupport } from '@/lib/utils/fetch' ;
4+
5+ /**
6+ * 代理请求处理函数
7+ */
8+ export async function POST ( request : NextRequest ) {
9+ try {
10+ // 获取请求数据
11+ const data = await request . json ( ) ;
12+ const { url, method = 'GET' , headers = { } , body } = data ;
13+
14+ if ( ! url ) {
15+ return NextResponse . json ( { error : '缺少必要的URL参数' } , { status : 400 } ) ;
16+ }
17+
18+ // 记录代理请求信息
19+ logger . info ( '[代理请求]' , method , url , {
20+ headers,
21+ '数据' : body || '无'
22+ } ) ;
23+
24+ // 准备请求选项
25+ const fetchOptions : RequestInit = {
26+ method,
27+ headers : {
28+ 'Content-Type' : 'application/json' ,
29+ ...headers
30+ }
31+ } ;
32+
33+ // 如果有请求体,添加到选项中
34+ if ( body ) {
35+ fetchOptions . body = JSON . stringify ( body ) ;
36+ }
37+
38+ // 使用支持自签名证书的fetch发送请求
39+ const response = await fetchWithSSLSupport ( url , fetchOptions ) ;
40+
41+ // 获取响应数据
42+ const responseData = await response . text ( ) ;
43+
44+ // 返回响应
45+ return new NextResponse ( responseData , {
46+ status : response . status ,
47+ headers : {
48+ 'Content-Type' : response . headers . get ( 'Content-Type' ) || 'application/json'
49+ }
50+ } ) ;
51+
52+ } catch ( error ) {
53+ // 记录错误
54+ logger . error ( '[代理请求错误]' , error ) ;
55+
56+ // 返回错误响应
57+ return NextResponse . json ( {
58+ error : '代理请求失败' ,
59+ message : error instanceof Error ? error . message : '未知错误'
60+ } , { status : 500 } ) ;
61+ }
62+ }
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ import { Icon } from "@iconify/react";
2929import { FlowTrafficChart } from "@/components/ui/flow-traffic-chart" ;
3030import { useRouter } from "next/navigation" ;
3131import { EndpointStatus } from '@prisma/client' ;
32- import { useGlobalSSE , useDashboardSSE } from '@/lib/hooks/use-sse' ;
32+ import { useGlobalSSE } from '@/lib/hooks/use-sse' ;
3333import { motion } from 'framer-motion' ;
3434import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
3535import {
@@ -300,23 +300,6 @@ export default function DashboardPage() {
300300 }
301301 }
302302 } ) ;
303-
304- // 使用仪表盘SSE监听流量趋势更新
305- useDashboardSSE ( {
306- onConnected : ( ) => {
307- console . log ( '仪表盘SSE连接成功' ) ;
308- } ,
309- onMessage : ( data ) => {
310- if ( data . type === 'dashboard_update' ) {
311- // 处理流量趋势更新
312- console . log ( '收到仪表盘更新:' , data ) ;
313- // 这里可以更新UI状态
314- }
315- } ,
316- onError : ( error ) => {
317- console . error ( '仪表盘SSE错误:' , error ) ;
318- }
319- } ) ;
320303
321304 // 初始化数据
322305 useEffect ( ( ) => {
Original file line number Diff line number Diff line change 1+ /**
2+ * 日志级别枚举
3+ */
4+ export enum LogLevel {
5+ DEBUG = 'DEBUG' ,
6+ INFO = 'INFO' ,
7+ WARN = 'WARN' ,
8+ ERROR = 'ERROR'
9+ }
10+
11+ /**
12+ * 日志工具类
13+ */
14+ class Logger {
15+ /**
16+ * 输出调试日志
17+ */
18+ debug ( ...args : any [ ] ) {
19+ console . debug ( `[${ new Date ( ) . toISOString ( ) } ] [DEBUG]` , ...args ) ;
20+ }
21+
22+ /**
23+ * 输出信息日志
24+ */
25+ info ( ...args : any [ ] ) {
26+ console . info ( `[${ new Date ( ) . toISOString ( ) } ] [INFO]` , ...args ) ;
27+ }
28+
29+ /**
30+ * 输出警告日志
31+ */
32+ warn ( ...args : any [ ] ) {
33+ console . warn ( `[${ new Date ( ) . toISOString ( ) } ] [WARN]` , ...args ) ;
34+ }
35+
36+ /**
37+ * 输出错误日志
38+ */
39+ error ( ...args : any [ ] ) {
40+ console . error ( `[${ new Date ( ) . toISOString ( ) } ] [ERROR]` , ...args ) ;
41+ }
42+ }
43+
44+ // 导出单例实例
45+ export const logger = new Logger ( ) ;
Original file line number Diff line number Diff line change 1+ -- AlterTable
2+ ALTER TABLE " Tunnel" ADD COLUMN " lastEventTime" DATETIME;
3+
4+ -- CreateIndex
5+ CREATE INDEX "Tunnel_lastEventTime_idx " ON " Tunnel" (" lastEventTime" );
You can’t perform that action at this time.
0 commit comments