Skip to content

Commit 0d2df48

Browse files
authored
fix: Livechat widget connecting to localhost instead of actual site url (#36332)
1 parent 8290892 commit 0d2df48

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

.changeset/late-donkeys-beg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rocket.chat/meteor": patch
3+
---
4+
5+
Fixes livechat widget attempting to connect to localhost instead of actual site url

apps/meteor/app/livechat/server/livechat.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { WebApp } from 'meteor/webapp';
77
import { settings } from '../../settings/server';
88
import { addServerUrlToIndex } from '../lib/Assets';
99

10-
const indexHtmlWithServerURL = addServerUrlToIndex((await Assets.getTextAsync('livechat/index.html')) || '');
10+
const indexHtmlWithServerURL = await Assets.getTextAsync('livechat/index.html');
1111

1212
function parseExtraAttributes(widgetData: string): string {
1313
const liveChatAdditionalScripts = settings.get<string>('Livechat_AdditionalWidgetScripts');
@@ -66,6 +66,6 @@ WebApp.connectHandlers.use('/livechat', (req, res, next) => {
6666
res.removeHeader('Content-Security-Policy');
6767
}
6868

69-
res.write(memoizedParseExtraAttributes(indexHtmlWithServerURL));
69+
res.write(memoizedParseExtraAttributes(addServerUrlToIndex(indexHtmlWithServerURL || '')));
7070
res.end();
7171
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { expect } from 'chai';
2+
import { describe, it, before, after } from 'mocha';
3+
4+
import { addServerUrlToIndex } from '../../../../../app/livechat/lib/Assets';
5+
6+
describe('addServerUrlToIndex', () => {
7+
before(() => {
8+
(global as any).__meteor_runtime_config__ = { ROOT_URL: 'http://localhost:3000' };
9+
});
10+
after(() => {
11+
delete (global as any).__meteor_runtime_config__;
12+
});
13+
14+
it('should do nothing if "file" has no <body> tag', () => {
15+
const file = addServerUrlToIndex('file');
16+
expect(file).to.equal('file');
17+
});
18+
it('should replace <body> with an script tag containing the SERVER_URL inside', () => {
19+
const file = addServerUrlToIndex('<html><body></body></html>');
20+
expect(file).to.equal("<html><body><script> SERVER_URL = 'http://localhost:3000'; </script></body></html>");
21+
});
22+
it('should remove any trailing / from the SERVER_URL', () => {
23+
(global as any).__meteor_runtime_config__ = { ROOT_URL: 'http://localhost:3000/' };
24+
const file = addServerUrlToIndex('<html><body></body></html>');
25+
expect(file).to.equal("<html><body><script> SERVER_URL = 'http://localhost:3000'; </script></body></html>");
26+
});
27+
it('should use the value from the global variable always', () => {
28+
const file = addServerUrlToIndex('<html><body></body></html>');
29+
expect(file).to.equal("<html><body><script> SERVER_URL = 'http://localhost:3000'; </script></body></html>");
30+
31+
(global as any).__meteor_runtime_config__ = { ROOT_URL: 'http://kodiak.rocket.chat/' };
32+
const file2 = addServerUrlToIndex('<html><body></body></html>');
33+
expect(file2).to.equal("<html><body><script> SERVER_URL = 'http://kodiak.rocket.chat'; </script></body></html>");
34+
});
35+
});

0 commit comments

Comments
 (0)