fix: Serve the static files from the webssh2_client module with a custom prefix '/ssh/assets' instead of just '/ssh'.

This commit is contained in:
Bill Church 2024-07-18 15:05:04 +00:00
parent 2d19f49091
commit 8fcf4b7b75
No known key found for this signature in database
4 changed files with 27 additions and 12 deletions

View file

@ -16,22 +16,22 @@ const sshRoutes = require('./routes')
* @returns {express.Application} The Express application instance
*/
function createApp() {
const app = express()
var app = express();
// Resolve the correct path to the webssh2_client module
const clientPath = path.resolve(__dirname, '..', 'node_modules', 'webssh2_client', 'client', 'public')
var clientPath = path.resolve(__dirname, '..', 'node_modules', 'webssh2_client', 'client', 'public');
// Handle POST and GET parameters
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// Serve static files from the webssh2_client module
app.use('/ssh', express.static(clientPath))
// Serve static files from the webssh2_client module with a custom prefix
app.use('/ssh/assets', express.static(clientPath));
// Use the SSH routes
app.use('/ssh', sshRoutes)
app.use('/ssh', sshRoutes);
return app
return app;
}
/**

View file

@ -1,6 +1,7 @@
// server
// app/connectionHandler.js
var path = require('path');
var fs = require('fs');
var extend = require('util')._extend;
function handleConnection(req, res, urlParams) {
@ -22,10 +23,18 @@ function handleConnection(req, res, urlParams) {
}
};
// You can process connectionParams here or pass them to the client
// Read the client.htm file
fs.readFile(path.join(clientPath, 'client.htm'), 'utf8', function(err, data) {
if (err) {
return res.status(500).send('Error loading client file');
}
// Serve the client HTML
res.sendFile(path.join(clientPath, 'client.htm'));
// Replace relative paths with the correct path
var modifiedHtml = data.replace(/(src|href)="(?!http|\/\/)/g, '$1="/ssh/assets/');
// Send the modified HTML
res.send(modifiedHtml);
});
}
module.exports = handleConnection;

5
package-lock.json generated
View file

@ -1842,6 +1842,11 @@
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.3.0.tgz",
"integrity": "sha512-akx5WBKAwMSg36qoHTuMMVncHWctlaDGslJASDYAhoLrzDUDCjZlOngNa/iC6lPm9aA0qk8pN5KnpmbJHSIIQQ=="
},
"fs": {
"version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",

View file

@ -36,6 +36,7 @@
"body-parser": "^1.15.2",
"debug": "~4.1.0",
"express": "^4.14.1",
"fs": "0.0.1-security",
"read-config-ng": "~3.0.7",
"socket.io": "~2.2.0",
"ssh2": "~0.8.9",