Add utility functions for handling public URLs and update API base URL logic

- Implement getProductionApiBaseUrl and normalizePublicUrl functions to manage API URLs based on the browser's origin.
- Update API base URL in request configuration to use getProductionApiBaseUrl.
- Enhance QR code handling in ParticipatingCompaniesTab and OutdoorFairList components to normalize URLs.
- Create a deployment script for frontend builds and server uploads.
- Add tests for the new URL utility functions.
This commit is contained in:
2026-07-15 08:46:40 +08:00
parent 5672bfcbc6
commit 00ba967685
7 changed files with 241 additions and 6 deletions

View File

@@ -0,0 +1,23 @@
import { getProductionApiBaseUrl, normalizePublicUrl } from '@/utils/publicUrl';
describe('public URL helpers', () => {
it('builds the production API base URL from the browser origin', () => {
expect(getProductionApiBaseUrl('http://39.98.44.136:6024')).toBe(
'http://39.98.44.136:6024/api/shihezi/',
);
});
it('replaces an internal backend origin with the browser origin', () => {
expect(
normalizePublicUrl(
'http://127.0.0.1:9091/h5/outdoor-fair/company.html?fairId=8&companyId=93007',
'http://39.98.44.136:6024',
),
).toBe('http://39.98.44.136:6024/h5/outdoor-fair/company.html?fairId=8&companyId=93007');
});
it('keeps an already public URL unchanged', () => {
const url = 'https://jobs.example.com/h5/outdoor-fair/company.html?fairId=8&companyId=93007';
expect(normalizePublicUrl(url, 'http://39.98.44.136:6024')).toBe(url);
});
});