github.com/grafana/pyroscope@v1.18.0/public/app/util/baseurl.ts (about)

     1  /**
     2   basename checks the "href" value of the <base> tag if available
     3   and returns the pathname part
     4   otherwise it return undefined
     5   */
     6  export function baseurl() {
     7    const base = document.querySelector('base') as HTMLBaseElement;
     8    if (!base) {
     9      return undefined;
    10    }
    11  
    12    const url = new URL(base.href, window.location.href);
    13    return url.pathname;
    14  }
    15  
    16  export function baseurlForAPI() {
    17    // When serving production, api path is one level above /ui
    18    // TODO(eh-am): remove when pages are moved to root
    19    return baseurl()?.replace('/ui', '');
    20  }
    21  
    22  export default baseurlForAPI;