Skip to content

Commit 0a0452c

Browse files
authored
fix: use dynamic port (#6)
* fix: use dynamic port * fix: update hardcoded port 8080 to 38123 in tests, CI, and docs * fix: replace hardcoded localhost:8080 with window.location.origin
1 parent 733711a commit 0a0452c

14 files changed

Lines changed: 34 additions & 36 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ jobs:
130130
shell: bash
131131
run: |
132132
for i in {1..30}; do
133-
curl -s http://localhost:8080 > /dev/null && break
133+
curl -s http://localhost:38123 > /dev/null && break
134134
sleep 1
135135
done
136136

__tests__/desktop-stub-utils.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,18 +260,18 @@ describe('extractMediaFilename', () => {
260260

261261
describe('buildMediaUrl', () => {
262262
test('constructs correct URL', () => {
263-
const result = buildMediaUrl('http://localhost:8080', 'abc123', 'image.png');
264-
expect(result).toBe('http://localhost:8080/api/media/abc123/image.png');
263+
const result = buildMediaUrl('http://localhost:38123', 'abc123', 'image.png');
264+
expect(result).toBe('http://localhost:38123/api/media/abc123/image.png');
265265
});
266266

267267
test('encodes filename', () => {
268-
const result = buildMediaUrl('http://localhost:8080', 'abc123', 'my image.png');
269-
expect(result).toBe('http://localhost:8080/api/media/abc123/my%20image.png');
268+
const result = buildMediaUrl('http://localhost:38123', 'abc123', 'my image.png');
269+
expect(result).toBe('http://localhost:38123/api/media/abc123/my%20image.png');
270270
});
271271

272272
test('handles special characters', () => {
273-
const result = buildMediaUrl('http://localhost:8080', 'abc123', 'image (1).png');
274-
expect(result).toBe('http://localhost:8080/api/media/abc123/image%20(1).png');
273+
const result = buildMediaUrl('http://localhost:38123', 'abc123', 'image (1).png');
274+
expect(result).toBe('http://localhost:38123/api/media/abc123/image%20(1).png');
275275
});
276276
});
277277

@@ -283,17 +283,17 @@ describe('extractBlobUrl', () => {
283283
});
284284

285285
test('extracts blob URL from string', () => {
286-
const blobUrl = 'blob:http://localhost:8080/550e8400-e29b-41d4-a716-446655440000';
286+
const blobUrl = 'blob:http://localhost:38123/550e8400-e29b-41d4-a716-446655440000';
287287
expect(extractBlobUrl(blobUrl)).toBe(blobUrl);
288288
});
289289

290290
test('extracts blob URL from wrapped path', () => {
291-
const wrapped = 'file:///path/to/blob:http://localhost:8080/550e8400-e29b-41d4-a716-446655440000/media/image.png';
292-
expect(extractBlobUrl(wrapped)).toBe('blob:http://localhost:8080/550e8400-e29b-41d4-a716-446655440000');
291+
const wrapped = 'file:///path/to/blob:http://localhost:38123/550e8400-e29b-41d4-a716-446655440000/media/image.png';
292+
expect(extractBlobUrl(wrapped)).toBe('blob:http://localhost:38123/550e8400-e29b-41d4-a716-446655440000');
293293
});
294294

295295
test('returns null for non-blob paths', () => {
296-
expect(extractBlobUrl('http://localhost:8080/image.png')).toBe(null);
296+
expect(extractBlobUrl('http://localhost:38123/image.png')).toBe(null);
297297
expect(extractBlobUrl('file:///path/to/image.png')).toBe(null);
298298
expect(extractBlobUrl('/media/image.png')).toBe(null);
299299
});

__tests__/logo-header.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fs from 'fs';
33
import path from 'path';
44
import os from 'os';
55

6-
const SERVER_PORT = Number.parseInt(process.env.SERVER_PORT || '8080', 10);
6+
const SERVER_PORT = Number.parseInt(process.env.SERVER_PORT || '38123', 10);
77
const SERVER_URL = process.env.SERVER_URL || `http://localhost:${SERVER_PORT}`;
88
const LOAD_TIMEOUT = Number.parseInt(process.env.LOAD_TIMEOUT || '30000', 10);
99
const LOGO_TIMEOUT = Number.parseInt(process.env.LOGO_TIMEOUT || '30000', 10);

__tests__/save.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import fs from 'fs';
44
import os from 'os';
55
import crypto from 'crypto';
66

7-
const SERVER_URL = process.env.SERVER_URL || 'http://localhost:8080';
7+
const SERVER_URL = process.env.SERVER_URL || 'http://localhost:38123';
88
const FIXTURES_DIR = path.resolve(import.meta.dir, '..', '.github/assets');
99
const tempFiles = [];
1010

__tests__/server-utils.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,12 @@ describe('generateX2TConfig', () => {
245245

246246
describe('extractFilePathFromUrl', () => {
247247
test('extracts path from OnlyOffice URL format', () => {
248-
const url = 'http://localhost:8080/api/onlyoffice/files/Users/test/file.xlsx';
248+
const url = 'http://localhost:38123/api/onlyoffice/files/Users/test/file.xlsx';
249249
expect(extractFilePathFromUrl(url)).toBe('/Users/test/file.xlsx');
250250
});
251251

252252
test('handles URL-encoded paths', () => {
253-
const url = 'http://localhost:8080/api/onlyoffice/files/Users/test/my%20file.xlsx';
253+
const url = 'http://localhost:38123/api/onlyoffice/files/Users/test/my%20file.xlsx';
254254
expect(extractFilePathFromUrl(url)).toBe('/Users/test/my file.xlsx');
255255
});
256256

@@ -260,8 +260,8 @@ describe('extractFilePathFromUrl', () => {
260260
});
261261

262262
test('returns null for non-matching URLs', () => {
263-
expect(extractFilePathFromUrl('http://localhost:8080/other/path')).toBe(null);
264-
expect(extractFilePathFromUrl('http://localhost:8080/api/convert')).toBe(null);
263+
expect(extractFilePathFromUrl('http://localhost:38123/other/path')).toBe(null);
264+
expect(extractFilePathFromUrl('http://localhost:38123/api/convert')).toBe(null);
265265
});
266266

267267
test('returns null for non-URL input', () => {

build-min.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ EDIT-BUILD-TEST WORKFLOW
131131
4. Start server and test:
132132
bun run server
133133

134-
5. Open browser to http://localhost:8080/open?filepath=/path/to/file.xlsx
134+
5. Open browser to http://localhost:38123/open?filepath=/path/to/file.xlsx
135135

136136

137137
RUNTIME LOADING

download-converter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const os = require('os');
2828
// Project files modified from upstream (excluding test/CI/docs):
2929
//
3030
// Server / Core:
31-
// server.js - Express server (port 8080)
31+
// server.js - Express server (dynamic port, default 38123)
3232
// server-utils.js - Server utility functions (added)
3333
// download-converter.js - Downloads ONLYOFFICE Desktop, extracts x2t (added)
3434
// package.json - Dependencies and scripts

editors/desktop-stub.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
// Synchronously upload image to server for persistence
6767
var xhr = new XMLHttpRequest();
6868
var serverFilename = 'dropped_' + Date.now() + '_' + i + '.' + ext;
69-
xhr.open('POST', 'http://localhost:8080/api/media/' + fileHash + '?filename=' + encodeURIComponent(serverFilename), false);
69+
xhr.open('POST', window.location.origin + '/api/media/' + fileHash + '?filename=' + encodeURIComponent(serverFilename), false);
7070
xhr.setRequestHeader('Content-Type', 'application/octet-stream');
7171

7272
// Send File directly (File extends Blob, XHR handles it)
@@ -96,8 +96,7 @@
9696
console.log('Creating AscDesktopEditor stub for browser environment');
9797

9898
// Server configuration
99-
var SERVER_PORT = 8080;
100-
var SERVER_BASE_URL = 'http://localhost:' + SERVER_PORT;
99+
var SERVER_BASE_URL = window.location.origin;
101100

102101
// Import utils from global (loaded before this script)
103102
var utils = window.DesktopStubUtils || {};

editors/offline-loader-proper.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@
132132
window._logTimings = logTimings;
133133

134134
// Server configuration
135-
const SERVER_PORT = 8080;
136-
const SERVER_BASE_URL = 'http://localhost:' + SERVER_PORT;
135+
const SERVER_BASE_URL = window.location.origin;
137136
window._ONLYOFFICE_SERVER_BASE_URL = SERVER_BASE_URL;
138137
window._ONLYOFFICE_DOC_BASE_URL = null;
139138
window._ONLYOFFICE_FILE_HASH = null;

server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const FONT_DATA_DIR = isAbsolutePath(process.env.FONT_DATA_DIR)
2626

2727
const app = express();
2828
app.use(compression());
29-
const PORT = 8080;
29+
const PORT = Number.parseInt(process.env.PORT || '38123', 10);
3030
const BASE_URL = `http://localhost:${PORT}`;
3131

3232
// Enable CORS

0 commit comments

Comments
 (0)