Skip to content

Commit bec1532

Browse files
Custom port support in Terminal manager (#1459)
* feat. custom port support * format
1 parent d6a8322 commit bec1532

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

src/components/terminal/terminal.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default class TerminalComponent {
3131
scrollOnUserInput: true,
3232
rows: options.rows || 24,
3333
cols: options.cols || 80,
34+
port: options.port || 8767,
3435
fontSize: terminalSettings.fontSize,
3536
fontFamily: terminalSettings.fontFamily,
3637
fontWeight: terminalSettings.fontWeight,
@@ -566,13 +567,16 @@ export default class TerminalComponent {
566567
rows: this.terminal.rows,
567568
};
568569

569-
const response = await fetch("http://localhost:8767/terminals", {
570-
method: "POST",
571-
headers: {
572-
"Content-Type": "application/json",
570+
const response = await fetch(
571+
`http://localhost:${this.options.port}/terminals`,
572+
{
573+
method: "POST",
574+
headers: {
575+
"Content-Type": "application/json",
576+
},
577+
body: JSON.stringify(requestBody),
573578
},
574-
body: JSON.stringify(requestBody),
575-
});
579+
);
576580

577581
if (!response.ok) {
578582
throw new Error(`HTTP error! status: ${response.status}`);
@@ -604,7 +608,7 @@ export default class TerminalComponent {
604608

605609
this.pid = pid;
606610

607-
const wsUrl = `ws://localhost:8767/terminals/${pid}`;
611+
const wsUrl = `ws://localhost:${this.options.port}/terminals/${pid}`;
608612

609613
this.websocket = new WebSocket(wsUrl);
610614

@@ -658,13 +662,16 @@ export default class TerminalComponent {
658662
if (!this.pid || !this.serverMode) return;
659663

660664
try {
661-
await fetch(`http://localhost:8767/terminals/${this.pid}/resize`, {
662-
method: "POST",
663-
headers: {
664-
"Content-Type": "application/json",
665+
await fetch(
666+
`http://localhost:${this.options.port}/terminals/${this.pid}/resize`,
667+
{
668+
method: "POST",
669+
headers: {
670+
"Content-Type": "application/json",
671+
},
672+
body: JSON.stringify({ cols, rows }),
665673
},
666-
body: JSON.stringify({ cols, rows }),
667-
});
674+
);
668675
} catch (error) {
669676
console.error("Failed to resize terminal:", error);
670677
}
@@ -953,9 +960,12 @@ export default class TerminalComponent {
953960

954961
if (this.pid && this.serverMode) {
955962
try {
956-
await fetch(`http://localhost:8767/terminals/${this.pid}/terminate`, {
957-
method: "POST",
958-
});
963+
await fetch(
964+
`http://localhost:${this.options.port}/terminals/${this.pid}/terminate`,
965+
{
966+
method: "POST",
967+
},
968+
);
959969
} catch (error) {
960970
console.error("Failed to terminate terminal:", error);
961971
}

0 commit comments

Comments
 (0)