From 04dbd7cde0e1e1a121b3b5b0e8a68009880a067a Mon Sep 17 00:00:00 2001 From: Dolu Date: Mon, 20 Dec 2021 17:01:10 +0100 Subject: [PATCH] fix lnd rest suffix url --- .gitignore | 8 +++++++- package.json | 4 ++-- src/backends/lnd-rest/lnd-rest.ts | 7 ++++++- src/backends/tools.ts | 5 +++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 234f9ca..b439abd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ node_modules/ dist/ -.vscode/ \ No newline at end of file +.vscode/ +coverage/ + +# Testing files +docker-compose.yml +test.js +index.js \ No newline at end of file diff --git a/package.json b/package.json index aee2ea9..a9a7376 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "una-wrapper", - "version": "0.0.8-beta", + "version": "0.0.9-beta", "description": "Universal Node API", "scripts": { "build": "tsup src/index.ts --format esm,cjs", @@ -39,4 +39,4 @@ "dist/" ], "types": "./dist/index.d.ts" -} +} \ No newline at end of file diff --git a/src/backends/lnd-rest/lnd-rest.ts b/src/backends/lnd-rest/lnd-rest.ts index 32b4444..e987740 100644 --- a/src/backends/lnd-rest/lnd-rest.ts +++ b/src/backends/lnd-rest/lnd-rest.ts @@ -111,6 +111,11 @@ export default class LndRest extends Backend { }) } + const urlObject = URLToObject(this.config.url) + if (urlObject.pathname !== '/') { + path = `${urlObject.pathname}${path}` + } + return { method, path, @@ -118,7 +123,7 @@ export default class LndRest extends Backend { headers: { 'Grpc-Metadata-macaroon': this.config.hexMacaroon }, - ...URLToObject(this.config.url) + ...urlObject } } diff --git a/src/backends/tools.ts b/src/backends/tools.ts index 1399dd1..ffc3f49 100644 --- a/src/backends/tools.ts +++ b/src/backends/tools.ts @@ -34,13 +34,14 @@ export const watchInvoices = (backend: IBackend, intervalMs: number | null = nul }, intervalMs ?? 5000) } -export const URLToObject = (urlStr: string): any => { +export const URLToObject = (urlStr: string): { protocol: string, hostname: string, port: string, pathname: string } => { const url = new URL(urlStr) return { protocol: url.protocol, hostname: url.hostname, - port: url.port + port: url.port, + pathname: url.pathname } }