diff --git a/api/src/repositories/project-participation-repository.ts b/api/src/repositories/project-participation-repository.ts index bb6bc91838..cd12c366ea 100644 --- a/api/src/repositories/project-participation-repository.ts +++ b/api/src/repositories/project-participation-repository.ts @@ -90,10 +90,6 @@ export class ProjectParticipationRepository extends BaseRepository { project_role pr ON pr.project_role_id = pp.project_role_id - LEFT JOIN - project_role pr - ON - pr.project_role_id = pp.project_role_id WHERE pp.project_id = ${projectId}; `; diff --git a/app/src/utils/Utils.test.ts b/app/src/utils/Utils.test.ts index 7a02ecb501..ea7dd1d928 100644 --- a/app/src/utils/Utils.test.ts +++ b/app/src/utils/Utils.test.ts @@ -12,10 +12,9 @@ import { } from './Utils'; describe('ensureProtocol', () => { - it('does nothing if string already has `http://`', async () => { - const url = 'http://someurl.com'; - const urlWithProtocol = ensureProtocol(url); - expect(urlWithProtocol).toEqual(url); + it('upgrades the URL if string begins with `http://`', async () => { + const urlWithProtocol = ensureProtocol('http://someurl.com'); + expect(urlWithProtocol).toEqual('https://someurl.com'); }); it('does nothing if string already has `https://`', async () => { @@ -24,6 +23,16 @@ describe('ensureProtocol', () => { expect(urlWithProtocol).toEqual(url); }); + it('adds http if string begins with `localhost`', async () => { + const urlWithProtocol = ensureProtocol('localhost:1234/test'); + expect(urlWithProtocol).toEqual('http://localhost:1234/test'); + }); + + it('does nothing if string begins with `http://localhost`', async () => { + const urlWithProtocol = ensureProtocol('http://localhost:1234/test'); + expect(urlWithProtocol).toEqual('http://localhost:1234/test'); + }); + it('adds `https://` when no protocol param is provided', async () => { const url = 'someurl.com'; const urlWithProtocol = ensureProtocol(url); diff --git a/app/src/utils/Utils.ts b/app/src/utils/Utils.ts index 06dc1e06ae..d6434d1628 100644 --- a/app/src/utils/Utils.ts +++ b/app/src/utils/Utils.ts @@ -6,14 +6,30 @@ import { LatLngBounds } from 'leaflet'; import moment from 'moment'; /** - * Checks if a url string starts with an `http(s)://` protocol, and adds `https://` if it does not. + * Checks if a url string starts with an `http[s]://` protocol, and adds `https://` if it does not. If the url + * begins with `localhost`, the `http` protocol is used. * * @param {string} url * @param {('http://' | 'https://')} [protocol='https://'] The protocol to add, if necessary. Defaults to `https://`. * @return {*} {string} the url which is guaranteed to have an `http(s)://` protocol. */ export const ensureProtocol = (url: string, protocol: 'http://' | 'https://' = 'https://'): string => { - return ((url.startsWith('http://') || url.startsWith('https://')) && url) || `${protocol}${url}`; + if (url.startsWith('localhost')) { + return `${'http://'}${url}`; + } + + if (url.startsWith('https://') || url.startsWith('http://localhost')) { + return url; + } + + if (url.startsWith('http://')) { + // If protocol is HTTPS, upgrade the URL + if (protocol === 'https://') { + return `${'https://'}${url.slice(7)}`; + } + } + + return `${protocol}${url}`; }; /** diff --git a/docker-compose.yml b/docker-compose.yml index c109196c61..084de7f2ab 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -114,7 +114,7 @@ services: - NODE_ENV=${NODE_ENV} - REACT_APP_NODE_ENV=${NODE_ENV} - PORT=${APP_PORT} - - REACT_APP_API_HOST=http://${API_HOST} + - REACT_APP_API_HOST=${API_HOST} - REACT_APP_API_PORT=${API_PORT} - REACT_APP_MAX_UPLOAD_NUM_FILES=${MAX_UPLOAD_NUM_FILES} - REACT_APP_MAX_UPLOAD_FILE_SIZE=${MAX_UPLOAD_FILE_SIZE}