From 3f4ce1d2fa48785aaf392cbf036615c0ba7daa60 Mon Sep 17 00:00:00 2001 From: Liran Cohen Date: Thu, 5 Sep 2024 19:40:41 -0400 Subject: [PATCH] config base url includes the port (#164) Currently the WalletConnect flow returns a fully qualified URL back to the caller, however it is returning it as a concatenation of `baseUril` and `port`. In most production systems the URL does not also include a port and so just a baseURL should be sufficient. The environment variable is now: `DWN_BASE_URL: 'http://localhost:3000'` --- src/config.ts | 2 +- src/http-api.ts | 2 +- tests/http-api.spec.ts | 5 ++--- tests/scenarios/dynamic-plugin-loading.spec.ts | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/config.ts b/src/config.ts index 389dd3a..53a550a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -15,7 +15,7 @@ export const config = { * The base external URL of this DWN. * This is used to construct URL paths such as the `Request URI` in the Web5 Connect flow. */ - baseUrl: process.env.DWN_BASE_URL || 'http://localhost', + baseUrl: process.env.DWN_BASE_URL || 'http://localhost:3000', /** * Port that server listens on. diff --git a/src/http-api.ts b/src/http-api.ts index 8d2fce3..af2ad7c 100644 --- a/src/http-api.ts +++ b/src/http-api.ts @@ -63,7 +63,7 @@ export class HttpApi { // create the Web5 Connect Server httpApi.web5ConnectServer = await Web5ConnectServer.create({ - baseUrl: `${config.baseUrl}:${config.port}`, + baseUrl: config.baseUrl, sqlTtlCacheUrl: config.ttlCacheUrl, }); diff --git a/tests/http-api.spec.ts b/tests/http-api.spec.ts index c49a3a4..6e07c9d 100644 --- a/tests/http-api.spec.ts +++ b/tests/http-api.spec.ts @@ -199,8 +199,7 @@ describe('http api', function () { describe('P0 Scenarios', function () { it('should be able to read and write a protocol record', async function () { - const dwnUrl = `${config.baseUrl}:${config.port}`; - await CommonScenarioValidator.sanityTestDwnReadWrite(dwnUrl, alice) + await CommonScenarioValidator.sanityTestDwnReadWrite(config.baseUrl, alice) }); }); @@ -924,7 +923,7 @@ describe('http api', function () { expect(resp.status).to.equal(200); const info = await resp.json(); - expect(info['url']).to.equal('http://localhost'); + expect(info['url']).to.equal('http://localhost:3000'); expect(info['server']).to.equal('@web5/dwn-server'); expect(info['registrationRequirements']).to.include('terms-of-service'); expect(info['registrationRequirements']).to.include( diff --git a/tests/scenarios/dynamic-plugin-loading.spec.ts b/tests/scenarios/dynamic-plugin-loading.spec.ts index 6bdbb36..f11a5cf 100644 --- a/tests/scenarios/dynamic-plugin-loading.spec.ts +++ b/tests/scenarios/dynamic-plugin-loading.spec.ts @@ -82,7 +82,6 @@ describe('Dynamic DWN plugin loading', function () { expect(customEventStreamConstructorSpy.calledOnce).to.be.true; // 3. Validate that the DWN instance is using the custom data store plugin. - const dwnUrl = `${dwnServerConfigCopy.baseUrl}:${dwnServerConfigCopy.port}`; - await CommonScenarioValidator.sanityTestDwnReadWrite(dwnUrl); + await CommonScenarioValidator.sanityTestDwnReadWrite(dwnServerConfigCopy.baseUrl); }); });