From ce0181710ef838c61dd50d952921a0f6e782d55e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20Caba=C3=A7o?= Date: Sat, 6 Apr 2024 02:01:05 +0100 Subject: [PATCH] fix: URL on fetch requests for channels (#286) --- src/RealtimeClient.ts | 10 ++++++---- test/socket_test.js | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/RealtimeClient.ts b/src/RealtimeClient.ts index 6412ce1..94c02be 100755 --- a/src/RealtimeClient.ts +++ b/src/RealtimeClient.ts @@ -327,7 +327,7 @@ export default class RealtimeClient { * @param name Channel name to create */ createChannel(name: string): Promise { - const url = `${this.httpEndpoint}/channels` + const url = `${this.httpEndpoint}/api/channels/` return this.fetch(url, { method: 'POST', headers: { @@ -350,7 +350,7 @@ export default class RealtimeClient { * @param name Channel name to delete. */ deleteChannel(name: string): Promise { - const url = `${this.httpEndpoint}/channels/${name}` + const url = `${this.httpEndpoint}/api/channels/${name}` return this.fetch(url, { method: 'DELETE', headers: { @@ -374,7 +374,7 @@ export default class RealtimeClient { * @param new_name New channel name. */ updateChannel(name: string, new_name: string): Promise { - const url = `${this.httpEndpoint}/channels/${name}` + const url = `${this.httpEndpoint}/api/channels/${name}` return this.fetch(url, { method: 'PATCH', headers: { @@ -395,7 +395,9 @@ export default class RealtimeClient { * Lists private channels */ listChannels(): Promise { - const url = `${this.httpEndpoint}/channels` + const url = `${this.httpEndpoint}/api/channels/` + console.log('!!!') + console.log(url) return this.fetch(url, { method: 'GET', headers: { diff --git a/test/socket_test.js b/test/socket_test.js index d842305..02f15f6 100755 --- a/test/socket_test.js +++ b/test/socket_test.js @@ -871,7 +871,7 @@ describe('createChannel', () => { const jwt = 'jwt' fetch = (url, opts) => { if ( - url == `http://localhost:4000/channels` && + url == `http://localhost:4000/api/channels/` && opts.method == 'POST' && opts.headers['Content-Type'] == 'application/json' && opts.headers['Authorization'] == `Bearer ${jwt}` && @@ -906,7 +906,7 @@ describe('deleteChannel', () => { const jwt = 'jwt' fetch = (url, opts) => { if ( - url == `http://localhost:4000/channels/${name}` && + url == `http://localhost:4000/api/channels/${name}` && opts.method == 'DELETE' && opts.headers['Authorization'] == `Bearer ${jwt}` && opts.headers['apikey'] == apikey @@ -940,7 +940,7 @@ describe('updateChannel', () => { const jwt = 'jwt' fetch = (url, opts) => { if ( - url == `http://localhost:4000/channels/${name}` && + url == `http://localhost:4000/api/channels/${name}` && opts.method == 'PATCH' && opts.headers['Authorization'] == `Bearer ${jwt}` && opts.headers['apikey'] == apikey @@ -975,7 +975,7 @@ describe('listChannels', () => { const jwt = 'jwt' fetch = (url, opts) => { if ( - url == `http://localhost:4000/channels` && + url == `http://localhost:4000/api/channels/` && opts.method == 'GET' && opts.headers['Authorization'] == `Bearer ${jwt}` && opts.headers['apikey'] == apikey