Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
I am creating a web application where i want to open ssh terminal (https://github.com/huashengdun/webssh) with an event listener on frontend and spawn() method in backend nodejs. I built an api to trigger that command from front-end but the problem is that the it's returning stderr which is fine but how can i handle that in my frontend as i want to show the terminal in but my api is not giving any response. Is there any other way to make this script.
This is my nodejs file where i am passing data from axios and executing the
wssh
command to start the webssh.
const child = spawn('wssh', [\
${body.cert_option}`, `${body.key_option}`, `--log-file-prefix=/var/www/html/myPanel/logs/terminal.log`]);child.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
return res.status(500).json({
success: 0,
data: data
});
})
child.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
return res.status(200).json({
success: 1,
data: data
});
});
child.on('error', (error) => {
console.log(`error: ${error}`);
return res.status(500).json({
success: 0,
message: "SSH connection error",
error: error
});
});
child.on('exit', (code, signal) => {
if (code) {
console.log(`child process exited with code ${code}`);
}
if (signal) {
console.log(`child process exited with signal ${signal}`);
}
});
});`
PS: my project is not completely on nodejs, only the api.
So here is something i want to create like this (source: aapanel):