chore: light refactoring

This commit is contained in:
Bill Church 2024-08-13 23:30:44 +00:00
parent cc8b014af8
commit 266f9876d3
No known key found for this signature in database
2 changed files with 18 additions and 22 deletions

View file

@ -54,23 +54,12 @@ function createApp() {
return { app, sessionMiddleware } return { app, sessionMiddleware }
} }
/**
* Creates and configures the HTTP server
* @param {express.Application} app - The Express application instance
* @returns {http.Server} The HTTP server instance
*/
function createServer(app) {
return http.createServer(app)
}
/** /**
* Configures Socket.IO with the given server * Configures Socket.IO with the given server
* @param {http.Server} server - The HTTP server instance * @param {http.Server} server - The HTTP server instance
* @param {Function} sessionMiddleware - The session middleware * @param {Function} sessionMiddleware - The session middleware
* @returns {import('socket.io').Server} The Socket.IO server instance * @returns {import('socket.io').Server} The Socket.IO server instance
*/ */
// var io = require('socket.io')(server, { serveClient: false, path: '/ssh/socket.io', origins: config.http.origins })
function configureSocketIO(server, sessionMiddleware) { function configureSocketIO(server, sessionMiddleware) {
const io = socketIo(server, { const io = socketIo(server, {
serveClient: false, serveClient: false,
@ -90,6 +79,15 @@ function configureSocketIO(server, sessionMiddleware) {
return io return io
} }
/**
* Creates and configures the HTTP server
* @param {express.Application} app - The Express application instance
* @returns {http.Server} The HTTP server instance
*/
function createServer(app) {
return http.createServer(app)
}
/** /**
* Gets the CORS configuration * Gets the CORS configuration
* @returns {Object} The CORS configuration object * @returns {Object} The CORS configuration object
@ -103,11 +101,11 @@ function getCorsConfig() {
} }
/** /**
* Sets up Socket.IO event listeners * Handles server errors
* @param {import('socket.io').Server} io - The Socket.IO server instance * @param {Error} err - The error object
*/ */
function setupSocketIOListeners(io) { function handleServerError(err) {
socketHandler(io, config) console.error("WebSSH2 server.listen ERROR:", err.code)
} }
/** /**
@ -135,11 +133,11 @@ function startServer() {
} }
/** /**
* Handles server errors * Sets up Socket.IO event listeners
* @param {Error} err - The error object * @param {import('socket.io').Server} io - The Socket.IO server instance
*/ */
function handleServerError(err) { function setupSocketIOListeners(io) {
console.error("WebSSH2 server.listen ERROR:", err.code) socketHandler(io, config)
} }
// Don't start the server immediately, export the function instead // Don't start the server immediately, export the function instead

View file

@ -36,12 +36,10 @@ router.get('/host/:host', auth, function (req, res) {
req.session.sshCredentials.host = host req.session.sshCredentials.host = host
req.session.sshCredentials.port = port req.session.sshCredentials.port = port
// Sanitize the sshCredentials object before logging // Sanitize and log the sshCredentials object
const sanitizedCredentials = sanitizeObject( const sanitizedCredentials = sanitizeObject(
JSON.parse(JSON.stringify(req.session.sshCredentials)) JSON.parse(JSON.stringify(req.session.sshCredentials))
); );
// Log the sanitized credentials
debug('/ssh//host/ Credentials: ', sanitizedCredentials); debug('/ssh//host/ Credentials: ', sanitizedCredentials);
handleConnection(req, res, { host: req.params.host }) handleConnection(req, res, { host: req.params.host })