Skip to content

Commit aeed03f

Browse files
committed
🔨 Enable debugging
Forward ports to allow for debugging outside docker container. Since this API (v4) is behind a proxy of previous versions of API, there is a conflict in port numbers, so instead of default Node.js inspect port (9229), other port number is used - 9339.
1 parent 8863082 commit aeed03f

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

‎bin/port-forward.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#! /usr/bin/env node
2+
3+
/*
4+
* A script that forwards port 9393 to 9339 to allow for attaching a debugger
5+
* from outside of the docker image.
6+
*/
7+
8+
const net = require('net');
9+
10+
net
11+
.createServer((from) => {
12+
try {
13+
const to = net.createConnection({
14+
host: 'localhost',
15+
port: 9339,
16+
});
17+
const close = () => {
18+
to.destroy();
19+
from.destroy();
20+
};
21+
from.pipe(to);
22+
to.pipe(from);
23+
to.on('close', close);
24+
to.on('error', close);
25+
to.on('end', close);
26+
from.on('close', close);
27+
from.on('error', close);
28+
from.on('end', close);
29+
} catch (e) {
30+
console.log('Unable to connect');
31+
from.destroy();
32+
}
33+
})
34+
.listen(9393);

‎docker-compose.integrated.yml

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ services:
77
dockerfile: ./env/api/Dockerfile
88
expose:
99
- '5100'
10+
- '9393'
11+
ports:
12+
- '9339:9393'
1013
volumes:
1114
- .:/srv/www
1215
- ../hpc-api-core:/srv/hpc-api-core

‎env/api/node.sh

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ if [ ! -d "node_modules" ]; then
77
npm install
88
fi
99

10+
echo "==> Starting port forwarding for debugger"
11+
node bin/port-forward.js &
12+
1013
echo "==> Waiting for postgres to start"
1114
/wait
1215

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"check-types": "tsc --noEmit",
1010
"install-and-link": "sh ./bin/install.sh",
1111
"start": "ts-node src/server.ts",
12-
"dev": "ts-node-dev --transpile-only --no-notify src/server.ts",
12+
"dev": "ts-node-dev --inspect=127.0.0.1:9339 --transpile-only --no-notify -- src/server.ts",
1313
"prepare": "husky install",
1414
"lint-prettier": "prettier -c .",
1515
"lint-eslint": "eslint --quiet .",

‎tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
"strictPropertyInitialization": false,
1818
"strict": true
1919
},
20-
"include": ["src/**/*.ts"],
20+
"include": ["src/**/*.ts", "bin"],
2121
"exclude": ["node_modules"]
2222
}

0 commit comments

Comments
 (0)