@@ -2,8 +2,9 @@ import type { NextRequest } from 'next/server';
22import { NextResponse } from 'next/server' ;
33import { getDatabase } from '../../../../server/database-prisma' ;
44import type { CreateServerData } from '../../../../types/server' ;
5+ import { withApiLogging } from '../../../../server/logging/withApiLogging' ;
56
6- export async function GET (
7+ export const GET = withApiLogging ( async function GET (
78 request : NextRequest ,
89 { params } : { params : Promise < { id : string } > }
910) {
@@ -28,16 +29,16 @@ export async function GET(
2829 }
2930
3031 return NextResponse . json ( server ) ;
31- } catch ( error ) {
32- console . error ( ' Error fetching server:' , error ) ;
32+ } catch {
33+ // Error handled by withApiLogging
3334 return NextResponse . json (
3435 { error : 'Failed to fetch server' } ,
3536 { status : 500 }
3637 ) ;
3738 }
38- }
39+ } , { redactBody : true } ) ;
3940
40- export async function PUT (
41+ export const PUT = withApiLogging ( async function PUT (
4142 request : NextRequest ,
4243 { params } : { params : Promise < { id : string } > }
4344) {
@@ -62,8 +63,9 @@ export async function PUT(
6263 ) ;
6364 }
6465
65- // Validate SSH port
66- if ( ssh_port !== undefined && ( ssh_port < 1 || ssh_port > 65535 ) ) {
66+ // Coerce and validate SSH port
67+ const port = ssh_port !== undefined ? parseInt ( String ( ssh_port ) , 10 ) : 22 ;
68+ if ( Number . isNaN ( port ) || port < 1 || port > 65535 ) {
6769 return NextResponse . json (
6870 { error : 'SSH port must be between 1 and 65535' } ,
6971 { status : 400 }
@@ -111,7 +113,7 @@ export async function PUT(
111113 auth_type : authType ,
112114 ssh_key,
113115 ssh_key_passphrase,
114- ssh_port : ssh_port ?? 22 ,
116+ ssh_port : port ,
115117 color,
116118 key_generated : key_generated ?? false ,
117119 ssh_key_path
@@ -124,7 +126,7 @@ export async function PUT(
124126 }
125127 ) ;
126128 } catch ( error ) {
127- console . error ( ' Error updating server:' , error ) ;
129+ // Error handled by withApiLogging
128130
129131 // Handle unique constraint violation
130132 if ( error instanceof Error && error . message . includes ( 'UNIQUE constraint failed' ) ) {
@@ -139,9 +141,9 @@ export async function PUT(
139141 { status : 500 }
140142 ) ;
141143 }
142- }
144+ } , { redactBody : true } ) ;
143145
144- export async function DELETE (
146+ export const DELETE = withApiLogging ( async function DELETE (
145147 request : NextRequest ,
146148 { params } : { params : Promise < { id : string } > }
147149) {
@@ -177,12 +179,12 @@ export async function DELETE(
177179 changes : 1
178180 }
179181 ) ;
180- } catch ( error ) {
181- console . error ( ' Error deleting server:' , error ) ;
182+ } catch {
183+ // Error handled by withApiLogging
182184 return NextResponse . json (
183185 { error : 'Failed to delete server' } ,
184186 { status : 500 }
185187 ) ;
186188 }
187- }
189+ } , { redactBody : true } ) ;
188190
0 commit comments