Skip to content

Commit 0cf087f

Browse files
committed
feat: add support for uri path
1 parent 637fec9 commit 0cf087f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

templates/typescript/templated/exported-class.template.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface Options {
1414
type: "websocket" | "http" | "https";
1515
host: string;
1616
port: number;
17+
path?: string;
1718
}
1819
}
1920
@@ -28,15 +29,19 @@ export class <%= className %> {
2829
if (options.transport === undefined || options.transport.type === undefined) {
2930
throw new Error("Invalid constructor params");
3031
}
31-
32+
const {type, host, port} = options.transport;
33+
let path = options.transport.path || "";
34+
if(path && path[0] !== "/") {
35+
path = "/" + path;
36+
}
3237
let transport;
33-
switch (options.transport.type) {
38+
switch (type) {
3439
case 'http':
3540
case 'https':
36-
transport = new HTTPTransport(options.transport.type + "://" + options.transport.host + ":" + options.transport.port)
41+
transport = new HTTPTransport(type + "://" + host + ":" + port + path)
3742
break;
3843
case 'websocket':
39-
transport = new WebSocketTransport("ws://" + options.transport.host + ":" + options.transport.port)
44+
transport = new WebSocketTransport("ws://" + host + ":" + port + path)
4045
break;
4146
default:
4247
throw new Error("unsupported transport");

0 commit comments

Comments
 (0)