datahub-web-react/BASE_PATH.md
DataHub's React frontend supports runtime base path detection, allowing the same build to be deployed at different URL paths (e.g., / or /datahub/) without requiring rebuild or reconfiguration.
The base path is determined through a hierarchical detection system:
/config or config endpoints/Use the resolveRuntimePath() function to resolve any asset path:
import { resolveRuntimePath } from '../utils/runtimeBasePath';
// Resolve asset paths
const logoUrl = resolveRuntimePath('/assets/logo.png');
const apiUrl = resolveRuntimePath('/api/graphql');
// Use in components
Use React Router's relative paths or resolve absolute paths:
import { resolveRuntimePath } from '../utils/runtimeBasePath';
// For React Router navigation (preferred - automatic)
<Link to="/datasets">Datasets</Link>
// For absolute URLs when needed
<a href={resolveRuntimePath('/browse')}>Browse</a>
import { resolveRuntimePath } from '../utils/runtimeBasePath';
// Resolve API endpoints
const endpoint = resolveRuntimePath('/api/v2/graphql');
fetch(endpoint, { ... });
The base path is configured in the backend Play application:
# datahub-frontend/conf/application.conf
datahub.basePath = "/datahub"
For containerized deployments:
# Docker/Kubernetes
DATAHUB_BASE_PATH=/datahub
# Serve at root
yarn start # Available at http://localhost:3000/
# Serve at subpath
yarn preview --base /datahub # Available at http://localhost:3000/datahub/
At Root Path:
DATAHUB_BASE_PATH="" docker run datahub-frontend
# Accessible at: https://datahub.company.com/
or unset
unset DATAHUB_BASE_PATH
docker run datahub-frontend
At Subpath:
DATAHUB_BASE_PATH=/datahub docker run datahub-frontend
# Accessible at: https://company.com/datahub/
The implementation uses standard HTML <base> tags and modern JavaScript features:
window.__DATAHUB_BASE_PATH__ is set correctlyresolveRuntimePath()# Clear cache and rebuild
yarn clean
yarn build
# Check base path detection
console.log(window.__DATAHUB_BASE_PATH__);
datahub-frontend/app/views/index.scala.htmlsrc/utils/runtimeBasePath.tssrc/ files using resolveRuntimePath()datahub-frontend/app/controllers/Application.javaThe system automatically handles: