UMB-CS-682-Team-03 / tracker

0 stars 0 forks source link

Clarification required on proper way to get base URL for an roundup tracker instance #41

Closed patel-malav closed 4 months ago

patel-malav commented 4 months ago

Look at - https://github.com/UMB-CS-682-Team-03/tracker/blob/d2dc8efed4860c7bfda21be4c69c8ee4a1d19eb7/html/classhelper.js#L116

Roundup helpurl is a relative link

e.g. - issue?@startwith=0&@template=help&properties=id,title&property=superseder&form=itemSynopsis&type=checkbox&@sort=title&@pagesize=10

To make an API call we need to construct an API URL which will have

<protocol>://<optional subdomain>.<domain>:<optional port>/<optional tracker name>/rest/data/<api data class>

thus this will lead to situations where some tracker instances may be deployed with optional tracker name and some may not.

eg. roundup tracker - in the URL there is no tracker name however the local dev has one

thus when the javascript called from different URLs may result into the code mentioned above have different URLs a baseURL

as such this can cause bugs in future iterations, where classhelper is need to be used on a page request with

/x/y/z/<file>?<query search param>

then this code will assume that <origin>/x/y/z to be base URL and append the /rest/data to it.

In current situation this is not an issue as all routes where classhelper is called are topLevel

rouilj commented 4 months ago

Does:

u = (new URL("relative href", document.location)).href

do what you want? If you pass an absolute URL, it appears to return the absolute URL in my testing. So this should work to normalize any url. Taken from stackoverflow.