Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

Keep the sub-path when pairing the mobile app with a server

Phaninder G36c7b771d6e1
diff --git a/frontend/src/lib/remote.js b/frontend/src/lib/remote.js
index ab80ddd64..dea811fb5 100644
--- a/frontend/src/lib/remote.js
+++ b/frontend/src/lib/remote.js
@@ -20,7 +20,7 @@ export function normalizeServerUrl(raw) {
try {
const u = new URL(withScheme)
if (!u.hostname) return null
- return u.origin
+ return u.origin + u.pathname.replace(/\/+$/, '')
} catch (e) { return null }
}
diff --git a/frontend/src/lib/remote.test.js b/frontend/src/lib/remote.test.js
index 45599a619..a23f30b3c 100644
--- a/frontend/src/lib/remote.test.js
+++ b/frontend/src/lib/remote.test.js
@@ -14,9 +14,11 @@ describe('normalizeServerUrl', () => {
expect(normalizeServerUrl('https://gym.example.com')).toBe('https://gym.example.com')
})
- it('trims whitespace and a trailing path/slash down to the origin', () => {
+ it('trims whitespace and trailing slashes but keeps a sub-path', () => {
expect(normalizeServerUrl(' gym.example.com/ ')).toBe('https://gym.example.com')
- expect(normalizeServerUrl('https://gym.example.com/some/path')).toBe('https://gym.example.com')
+ expect(normalizeServerUrl('https://gym.example.com/some/path')).toBe('https://gym.example.com/some/path')
+ expect(normalizeServerUrl('https://host/opengym/')).toBe('https://host/opengym')
+ expect(normalizeServerUrl('https://host/opengym///')).toBe('https://host/opengym')
})
it('rejects empty or unusable input', () => {