Skip to content

Commit afc45a7

Browse files
authored
Merge pull request #1 from voidvoxel/main
Add port property to `PortalNode`
2 parents 6c0f510 + 42b1ee1 commit afc45a7

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/ports/PortalClient.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function prepareConfig(config, opts) {
4141

4242
class PortalClient extends PortalNode {
4343
constructor(opts, cb=null) {
44-
super();
44+
super(opts.port);
4545

4646
if (!opts.unixSocket && !+opts.port) {
4747
throw "Invalid proxy port.";

src/ports/PortalNode.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
class PortalNode {
2-
constructor() {
2+
#port
3+
4+
constructor(port) {
35
this._isRunning = false;
6+
7+
if (typeof port !== "number") throw new TypeError(`Expected "port" to be of type "number" but instead received ${JSON.stringify(port)}`);
8+
9+
this.#port = port;
10+
}
11+
12+
get port() {
13+
return this.#port;
414
}
515

616
async close() {

src/ports/PortalServer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ function prepareConfig(config, opts) {
4747

4848
class PortalServer extends PortalNode {
4949
constructor(opts, callback) {
50-
super();
51-
5250
if (!opts.unixSocket && !+opts.port) {
5351
throw "Invalid proxy port.";
5452
}
@@ -57,6 +55,8 @@ class PortalServer extends PortalNode {
5755
throw "Cannot simultaneously listen to both a port and Unix domain socket.";
5856
}
5957

58+
super(opts.port);
59+
6060
this._config = {};
6161

6262
prepareConfig(this._config, opts);

0 commit comments

Comments
 (0)