UNPKG

webssh2-server

Version:

A Websocket to SSH2 gateway using xterm.js, socket.io, ssh2

41 lines (40 loc) 1.08 kB
// app/utils/response-helpers.ts // HTTP response helper utilities import { HTTP } from '../constants.js'; /** * Send unauthorized response with authentication header */ export function sendUnauthorized(res, message = 'Authentication required') { res.setHeader(HTTP.AUTHENTICATE, HTTP.REALM); res.status(HTTP.UNAUTHORIZED).send(message); } /** * Send bad request response */ export function sendBadRequest(res, message) { res.status(400).send(message); } /** * Send gateway timeout response */ export function sendGatewayTimeout(res, host, port) { res.status(504).send(`Gateway Timeout: SSH connection to ${host}:${port} timed out`); } /** * Send bad gateway response */ export function sendBadGateway(res, host, port, error) { res.status(502).send(`Bad Gateway: SSH connection to ${host}:${port} failed - ${error}`); } /** * Send success response */ export function sendSuccess(res, message) { res.status(HTTP.OK).send(message); } /** * Send JSON response */ export function sendJson(res, data, status = 200) { res.status(status).json(data); }