Skip to content

Commit 0fe5ea3

Browse files
Fix terminal: socket ref, PTY newlines, bash -i, public mode. Fixes JavaScriptSolidServer#237
1 parent 2ebd58e commit 0fe5ea3

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export function createServer(options = {}) {
253253

254254
// Register terminal (WebSocket shell) if enabled
255255
if (terminalEnabled) {
256-
fastify.register(terminalPlugin, { path: '/.terminal' });
256+
fastify.register(terminalPlugin, { path: '/.terminal', public: options.public || false });
257257
}
258258

259259
// Register tunnel proxy if enabled

src/terminal/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export async function terminalPlugin(fastify, options = {}) {
4848
});
4949

5050
fastify.get(wsPath, { websocket: true }, async (connection, request) => {
51-
const socket = connection.socket;
51+
const socket = connection.socket || connection;
5252

5353
// Authenticate — query param token support for browser WebSocket
5454
const queryToken = request.query?.token;
@@ -57,14 +57,14 @@ export async function terminalPlugin(fastify, options = {}) {
5757
}
5858
const { webId } = await getWebIdFromRequestAsync(request);
5959

60-
if (!webId) {
60+
if (!webId && !options.public) {
6161
socket.send(JSON.stringify({ type: 'error', message: 'Authentication required' }));
6262
socket.close();
6363
return;
6464
}
6565

6666
// Spawn shell
67-
const shell = spawn('/bin/sh', [], {
67+
const shell = spawn('/bin/bash', ['-i'], {
6868
stdio: ['pipe', 'pipe', 'pipe'],
6969
env: { ...process.env, TERM: 'xterm-256color' },
7070
});
@@ -74,14 +74,14 @@ export async function terminalPlugin(fastify, options = {}) {
7474
// Pipe shell stdout to WebSocket
7575
shell.stdout.on('data', (data) => {
7676
if (socket.readyState === 1) {
77-
try { socket.send(data); } catch { /* socket closed */ }
77+
try { socket.send(data.toString().replace(/\n/g, '\r\n')); } catch { /* socket closed */ }
7878
}
7979
});
8080

8181
// Pipe shell stderr to WebSocket
8282
shell.stderr.on('data', (data) => {
8383
if (socket.readyState === 1) {
84-
try { socket.send(data); } catch { /* socket closed */ }
84+
try { socket.send(data.toString().replace(/\n/g, '\r\n')); } catch { /* socket closed */ }
8585
}
8686
});
8787

0 commit comments

Comments
 (0)