From 51f03f251f739caf6538b87efed79e7cdaf5b16a Mon Sep 17 00:00:00 2001 From: Luis Pais Date: Sun, 9 Oct 2022 14:06:16 +0100 Subject: [PATCH] feat: changed client code to dynamically perform calls to the domain in the browser address bar --- app/client/src/api/config.ts | 15 --------------- app/client/src/api/generator.spec.ts | 15 +-------------- app/client/src/api/generator.ts | 9 +-------- app/components/StepsOfStepper/ScanQRStep.tsx | 1 + 4 files changed, 3 insertions(+), 37 deletions(-) delete mode 100644 app/client/src/api/config.ts diff --git a/app/client/src/api/config.ts b/app/client/src/api/config.ts deleted file mode 100644 index ffe14634..00000000 --- a/app/client/src/api/config.ts +++ /dev/null @@ -1,15 +0,0 @@ -let host; -let protocol; -let port; - -if (!host && !protocol && !port) { - host = window.location.host.split(':')[0]; - protocol = 'http'; - port = 3131; -} - -export default { - host, - port, - protocol, -}; diff --git a/app/client/src/api/generator.spec.ts b/app/client/src/api/generator.spec.ts index d0dcebaf..6f1c0437 100644 --- a/app/client/src/api/generator.spec.ts +++ b/app/client/src/api/generator.spec.ts @@ -1,19 +1,6 @@ import generator from './generator'; import { TEST_PORT, TEST_HOST, TEST_PROTOCOL } from './mocks/generatorTestVariables'; -// how to use local variables in jest mock to get rid of hoisting mocks to top most code block: -//stackoverflow.com/questions/44649699/service-mocked-with-jest-causes-the-module-factory-of-jest-mock-is-not-allowe -jest.mock('./config', () => { - const generatorTestVariables = require('./mocks/generatorTestVariables'); - - return { - host: generatorTestVariables.TEST_HOST, - protocol: generatorTestVariables.TEST_PROTOCOL, - port: generatorTestVariables.TEST_PORT, - }; -}); - - describe('generator.ts', () => { afterEach(() => { jest.clearAllMocks(); @@ -27,7 +14,7 @@ describe('generator.ts', () => { const result = generator(roomID); expect(result).toMatch( - `${TEST_PROTOCOL}://${TEST_HOST}:${TEST_PORT}/${roomID}` + `/${roomID}` ); }); }); diff --git a/app/client/src/api/generator.ts b/app/client/src/api/generator.ts index 1788bc49..7d6463e2 100644 --- a/app/client/src/api/generator.ts +++ b/app/client/src/api/generator.ts @@ -1,13 +1,6 @@ -import config from './config'; export default (resourceName = '') => { - const { port, protocol, host } = config; - const resourcePath = resourceName; - if (!host) { - return `/localhost`; - } - - return `${protocol}://${host}:${port}/${resourcePath}`; + return `/${resourcePath}`; }; diff --git a/app/components/StepsOfStepper/ScanQRStep.tsx b/app/components/StepsOfStepper/ScanQRStep.tsx index 9ba5e479..59547260 100644 --- a/app/components/StepsOfStepper/ScanQRStep.tsx +++ b/app/components/StepsOfStepper/ScanQRStep.tsx @@ -20,6 +20,7 @@ import { IpcEvents } from '../../main/IpcEvents.enum'; const { port } = config; +// can the comment bellow be removed? Because the port is being defined in the config file, although it can't be changed after bundling I think // TODO: change port to user defined port, if it is really defined const CLIENT_VIEWER_PORT = isProduction() ? port : '3000';