javascript-solid-server 0.0.118 → 0.0.119
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/server.js +1 -1
- package/src/terminal/index.js +6 -5
package/package.json
CHANGED
package/src/server.js
CHANGED
|
@@ -253,7 +253,7 @@ export function createServer(options = {}) {
|
|
|
253
253
|
|
|
254
254
|
// Register terminal (WebSocket shell) if enabled
|
|
255
255
|
if (terminalEnabled) {
|
|
256
|
-
fastify.register(terminalPlugin, { path: '/.terminal' });
|
|
256
|
+
fastify.register(terminalPlugin, { path: '/.terminal', public: options.public || false });
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
// Register tunnel proxy if enabled
|
package/src/terminal/index.js
CHANGED
|
@@ -48,7 +48,7 @@ export async function terminalPlugin(fastify, options = {}) {
|
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
fastify.get(wsPath, { websocket: true }, async (connection, request) => {
|
|
51
|
-
const socket = connection.socket;
|
|
51
|
+
const socket = connection.socket || connection;
|
|
52
52
|
|
|
53
53
|
// Authenticate — query param token support for browser WebSocket
|
|
54
54
|
const queryToken = request.query?.token;
|
|
@@ -57,14 +57,15 @@ export async function terminalPlugin(fastify, options = {}) {
|
|
|
57
57
|
}
|
|
58
58
|
const { webId } = await getWebIdFromRequestAsync(request);
|
|
59
59
|
|
|
60
|
-
if (!webId) {
|
|
60
|
+
if (!webId && !options.public) {
|
|
61
61
|
socket.send(JSON.stringify({ type: 'error', message: 'Authentication required' }));
|
|
62
62
|
socket.close();
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
// Spawn shell
|
|
67
|
-
const
|
|
67
|
+
const shellCommand = process.env.SHELL || 'bash';
|
|
68
|
+
const shell = spawn(shellCommand, ['-i'], {
|
|
68
69
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
69
70
|
env: { ...process.env, TERM: 'xterm-256color' },
|
|
70
71
|
});
|
|
@@ -74,14 +75,14 @@ export async function terminalPlugin(fastify, options = {}) {
|
|
|
74
75
|
// Pipe shell stdout to WebSocket
|
|
75
76
|
shell.stdout.on('data', (data) => {
|
|
76
77
|
if (socket.readyState === 1) {
|
|
77
|
-
try { socket.send(data); } catch { /* socket closed */ }
|
|
78
|
+
try { socket.send(data.toString().replace(/\r?\n/g, '\r\n')); } catch { /* socket closed */ }
|
|
78
79
|
}
|
|
79
80
|
});
|
|
80
81
|
|
|
81
82
|
// Pipe shell stderr to WebSocket
|
|
82
83
|
shell.stderr.on('data', (data) => {
|
|
83
84
|
if (socket.readyState === 1) {
|
|
84
|
-
try { socket.send(data); } catch { /* socket closed */ }
|
|
85
|
+
try { socket.send(data.toString().replace(/\r?\n/g, '\r\n')); } catch { /* socket closed */ }
|
|
85
86
|
}
|
|
86
87
|
});
|
|
87
88
|
|