diff --git a/.changeset/late-donkeys-beg.md b/.changeset/late-donkeys-beg.md new file mode 100644 index 00000000000..ab0fd46a9bb --- /dev/null +++ b/.changeset/late-donkeys-beg.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +Fixes livechat widget attempting to connect to localhost instead of actual site url diff --git a/apps/meteor/app/livechat/server/livechat.ts b/apps/meteor/app/livechat/server/livechat.ts index 795deaba345..8928ee826ea 100644 --- a/apps/meteor/app/livechat/server/livechat.ts +++ b/apps/meteor/app/livechat/server/livechat.ts @@ -7,7 +7,7 @@ import { WebApp } from 'meteor/webapp'; import { settings } from '../../settings/server'; import { addServerUrlToIndex } from '../lib/Assets'; -const indexHtmlWithServerURL = addServerUrlToIndex((await Assets.getTextAsync('livechat/index.html')) || ''); +const indexHtmlWithServerURL = await Assets.getTextAsync('livechat/index.html'); function parseExtraAttributes(widgetData: string): string { const liveChatAdditionalScripts = settings.get('Livechat_AdditionalWidgetScripts'); @@ -66,6 +66,6 @@ WebApp.connectHandlers.use('/livechat', (req, res, next) => { res.removeHeader('Content-Security-Policy'); } - res.write(memoizedParseExtraAttributes(indexHtmlWithServerURL)); + res.write(memoizedParseExtraAttributes(addServerUrlToIndex(indexHtmlWithServerURL || ''))); res.end(); }); diff --git a/apps/meteor/tests/unit/app/livechat/lib/assets.spec.ts b/apps/meteor/tests/unit/app/livechat/lib/assets.spec.ts new file mode 100644 index 00000000000..dd9944498ae --- /dev/null +++ b/apps/meteor/tests/unit/app/livechat/lib/assets.spec.ts @@ -0,0 +1,35 @@ +import { expect } from 'chai'; +import { describe, it, before, after } from 'mocha'; + +import { addServerUrlToIndex } from '../../../../../app/livechat/lib/Assets'; + +describe('addServerUrlToIndex', () => { + before(() => { + (global as any).__meteor_runtime_config__ = { ROOT_URL: 'http://localhost:3000' }; + }); + after(() => { + delete (global as any).__meteor_runtime_config__; + }); + + it('should do nothing if "file" has no tag', () => { + const file = addServerUrlToIndex('file'); + expect(file).to.equal('file'); + }); + it('should replace with an script tag containing the SERVER_URL inside', () => { + const file = addServerUrlToIndex(''); + expect(file).to.equal(""); + }); + it('should remove any trailing / from the SERVER_URL', () => { + (global as any).__meteor_runtime_config__ = { ROOT_URL: 'http://localhost:3000/' }; + const file = addServerUrlToIndex(''); + expect(file).to.equal(""); + }); + it('should use the value from the global variable always', () => { + const file = addServerUrlToIndex(''); + expect(file).to.equal(""); + + (global as any).__meteor_runtime_config__ = { ROOT_URL: 'http://kodiak.rocket.chat/' }; + const file2 = addServerUrlToIndex(''); + expect(file2).to.equal(""); + }); +});