Skip to content

Commit d1ab2b4

Browse files
authored
feat: Allow callers of debugServerMain.ts to specify the host (#1006)
This change allows callers of debugServerMain.ts to be able to provide what address the DAP listener will bind to. This prevents random eavesdroppers from listening into the DAP. Fixes: #1005
1 parent ff3de04 commit d1ab2b4

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/debugServer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Configurator {
8383
}
8484
}
8585

86-
export function startDebugServer(port: number): Promise<IDisposable> {
86+
export function startDebugServer(port: number, host?: string): Promise<IDisposable> {
8787
return new Promise((resolve, reject) => {
8888
const server = net
8989
.createServer(async socket => {
@@ -115,7 +115,7 @@ export function startDebugServer(port: number): Promise<IDisposable> {
115115
const configurator = new Configurator(connection.dap());
116116
})
117117
.on('error', reject)
118-
.listen(port, () => {
118+
.listen({ port, host }, () => {
119119
console.log(`Debug server listening at ${(server.address() as net.AddressInfo).port}`);
120120
resolve({
121121
dispose: () => {

src/debugServerMain.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,17 @@
44

55
import { startDebugServer } from './debugServer';
66

7-
startDebugServer(process.argv.length >= 3 ? +process.argv[2] : 0);
7+
let port = 0;
8+
let host: string | undefined;
9+
if (process.argv.length >= 3) {
10+
// Interpret the argument as either a port number, or 'address:port'.
11+
const address = process.argv[2];
12+
const colonIndex = address.lastIndexOf(':');
13+
if (colonIndex === -1) {
14+
port = +address;
15+
} else {
16+
host = address.substring(0, colonIndex);
17+
port = +address.substring(colonIndex + 1);
18+
}
19+
}
20+
startDebugServer(port, host);

0 commit comments

Comments
 (0)