(socket: net.Socket, id: number, error: any)
| 583 | } |
| 584 | |
| 585 | function sendError (socket: net.Socket, id: number, error: any) { |
| 586 | const errorResponse = { |
| 587 | id, |
| 588 | type: 'error', |
| 589 | error: { |
| 590 | message: error.message, |
| 591 | stack: error.stack, |
| 592 | status: error.status, |
| 593 | statusText: error.statusText, |
| 594 | data: error.data, |
| 595 | }, |
| 596 | } |
| 597 | const responseJSON = JSON.stringify(errorResponse) |
| 598 | const messageBuffer = Buffer.from(responseJSON, 'utf-8') |
| 599 | const messageLength = messageBuffer.length |
| 600 | |
| 601 | // Pre-allocate single buffer for length + message to avoid Buffer.concat() |
| 602 | const fullMessage = Buffer.alloc(4 + messageLength) |
| 603 | fullMessage.writeUInt32BE(messageLength, 0) |
| 604 | messageBuffer.copy(fullMessage, 4) |
| 605 | |
| 606 | socket.write(fullMessage, (err) => { |
| 607 | if (err) { |
| 608 | // Failed to send error response - connection likely closed |
| 609 | } |
| 610 | }) |
| 611 | } |
| 612 | |
| 613 | export type ViteNodeServerOptions = { |
| 614 | baseURL: string |
no outgoing calls
no test coverage detected
searching dependent graphs…