Skip to content

Use relative paths#164

Open
aviborg wants to merge 1 commit intobrian7704:masterfrom
aviborg:feature/use-relative-paths
Open

Use relative paths#164
aviborg wants to merge 1 commit intobrian7704:masterfrom
aviborg:feature/use-relative-paths

Conversation

@aviborg
Copy link
Copy Markdown

@aviborg aviborg commented Jan 19, 2026

Summary

I have refactored the codebase to use relative paths, which allows the application to be deployed in any subfolder (e.g., example.com/opentakserver/)

THE BACKEND HAS NOT BEEN TESTED OR FIXED AGAINST THIS CHANGE YET !!!

Key Changes Made:

  • Vite Configuration: Updated vite.config.mjs to set base: './'. This ensures that all bundled assets (JS, CSS, etc.) are linked using relative paths.
  • Relative Asset Links: Modified index.html to remove leading slashes from manually linked assets like the favicon, web manifest, and the main entry script.
  • Relative API Routes: Updated src/apiRoutes.tsx to remove leading slashes from all API endpoints. This makes them relative to the folder where the UI is served.
  • Localization & Assets: Updated src/i18n.js (translation files) and src/DefaultLayout.tsx to use relative paths.
  • Map Icons: Modified src/pages/Map/Map.tsx to ensure default Leaflet marker icons are loaded relatively.
  • HashRouter Implementation: I switched the application from BrowserRouter to HashRouter in src/App.tsx. Why? This is the most robust way to support subfolder deployments without requiring any server-side configuration (like Nginx try_files or .env variables). All SPA routing is now handled after the # in the URL, making the app completely agnostic to its parent folder depth.

Summary of modified files:

  • vite.config.mjs: Added base: './'
  • index.html: Removed leading slashes from all and <script> tags.
  • src/apiRoutes.tsx: Removed leading slashes from all 60+ API endpoints.
  • src/i18n.js: Updated loadPath to be relative.
  • src/DefaultLayout.tsx:: Updated alert.mp3 path.
  • src/pages/Map/Map.tsx: Updated Leaflet icon paths.
  • public/site.webmanifest: Updated internal icon paths.
  • src/App.tsx: Replaced BrowserRouter with HashRouter.

The application should now load correctly at example.com/opentakserver/ (or any other path) by simply pointing your document root to the appropriate folder.

Fixes #163

…i18n, with Vite configured for relative asset paths.
@Knobee
Copy link
Copy Markdown

Knobee commented Apr 27, 2026

Tested this against current master (03803d9) — substantive changes still apply cleanly via 3-way merge, type-check passes, and Vite build succeeds. The auth-bypass guard from #179 doesn't conflict (your version of the same change happens to be identical). The new language: '/api/language' route added since you opened this gets de-slashed correctly by the 3-way merge.

Two things would need to change before this is mergeable IMO:

1. Formatting churn (~70 of 158 changed lines). Several files were reformatted by what looks like a different editor config — the actual leading-slash removals are buried in unrelated whitespace changes:

File Real changes Whitespace-only changes
src/pages/Map/Map.tsx 7 ~100
src/App.tsx 6 ~24
src/DefaultLayout.tsx 2 ~18
public/site.webmanifest 4 trailing newline

Examples: eud:anyeud: any, {t}{ t }, JSX indent shifts from 4 → 2 spaces, {navigate('/profile')}{ navigate('/profile') }. None of these are required for the relative-paths fix and they make the PR painful to review. Could you revert the formatting-only changes and keep only the slash removals?

2. BrowserRouterHashRouter switch in src/App.tsx. This makes every URL look like https://example.com/opentakserver/#/users instead of https://example.com/opentakserver/users. That's a user-visible URL change — it breaks bookmarks, breaks share links, and changes how the app shows up in browser history and external referrers. Since you're already setting base: './' in vite.config.mjs and stripping leading slashes from API routes, BrowserRouter should work for subdir deployments without HashRouter. Is there a specific deployment scenario where Vite base + BrowserRouter falls short? If not, dropping HashRouter would let this be a pure asset-path fix.

Backend note: Your PR description flags that the backend hasn't been tested against this change. The loadPath: "locales/..." and other now-relative paths assume the browser resolves them against the page URL — that's fine for the SPA shell, but it might be worth a quick sanity test that the backend routes (especially /api/casevac upload handlers, /Marti/... endpoints called server-side) don't break when the UI is hosted at a subpath.

Happy to help with the formatting-revert if you'd like — or I can open a follow-up PR taking your commit and stripping the noise on top of current master, co-credited to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use relative paths for assets and more

2 participants