tavyandy97/span-tree

Request URL seems to be wrong.

huzisuke opened this issue · 9 comments

Thank you for developing great extension.
I download it as chrome extension but it seems not to work.
The side bar box is keep loading.

Checking on the developer tool, it shows 404.
Our gitlab URL is "http://DOMAIN/gitlab/REPOSITORY/..." but the requested URL is "http://DOMAIN/api/v4/...".
The word "gitlab" seems to be excluded.
As I insert "gitlab" between DOMAIN and api, chrome returns json.

Does someone know how to fix it?

Hey @huzisuke ,
Glad to know that you're finding SpanTree useful!

The reason we assumed GitLab is hosted on a subdomain is because GitLab recommends you to host your git instance on a subdomain rather than on a relative url.

As you can see in the code we've hardcoded the API url to be in the form of SUBDOMAIN.DOMAIN.XYZ /api/v4/projects/.

However, one possible solution, I came up with is to extract the relative url from the window object provided by GitLab. Could you help me out and post the window.gon object from your browser console so that I can confirm that GitLab does indeed send relative paths if any. (Specifically want to confirm whether the window.gon.relative_url_root contains the relative path). If so I'll be able to fix and publish it soon.

Thank you for reporting the issue and look forward to solving the problem

Hi @tavyandy97
Thanks for replying and considering the solution.

I didn't know the GitLab recommendation because the environment was built by my colleague.
But I notice other GitLab extensions show same error...

Anyway, I post window.gon.relative_url_root to the console and it returns '/gitlab'.

Hey @huzisuke ,
Thanks a lot for the quick response and help in debugging the issue. Needed one last help to verify the fix that I created tavyandy97-relativeUrl. Could you checkout the branch and try the fix out before I published the changes?

Thanks a lot again for the support! Let me know if you face any issues in building the extension (Please take reference from
README.md).

Hi @tavyandy97 ,
Thank you for creating debug branch.

Unfortunately, I could build but it show errors.

  1. The error is "TypeError: Cannot read properties of undefined (reading 'relative_url_root')".
    Every 'window.gon.relative_url_root' is seems to occur this error. There is the 'window' object at that timing, but it doesn't have 'gon' property yet.

  2. Tree links is not correct.
    After I rewrote all 'window.gon.relative_url_root' to '/gitlab', the extensions seems to work fine.
    However, I click one of the file, the window showed 404.
    The link is 'http://DOMAIN/gitlab/gitlab/REPOSITORY/blob/BRANCH/..'.
    In my environment, 'http://DOMAIN/gitlab/REPOSITORY/-/blob/BRANCH/..' will be expected.

I'm happy for your appreciation.

Hi @huzisuke ,
Tried debugging the issue and you're right as it seems like we do not get the gon object in the window when SpanTree is trying to access it. Since we cannot delay the execution of SpanTree till the rest of the scripts run we'll have to figure another way out to extract the relative URL.

For now I've tried to push a fix for the same by extracting the relative URL by splitting the current url by repository parent. Although I've tested the fix and ideally should work, I'd appreciate it if you could verify it? tavyandy97-relativeUrl

Sorry for the to and fro and thanks a lot once again.

Thanks a lot for new version!
The 'gon' property error was disapper!
The SpanTree tab is shown every time.

Sometimes I found 404 error on the developer tool.
These are seemed to access incorrect URL.

  • case1
    DOMAIN/gitlab/gitlab/GROUP/REPOSITORY/
    -> This should be DOMAIN/gitlab/GROUP/REPOSITORY/

  • case2
    DOMAIN/gitlab/PROJECT/gitlab/GROUP/SUBGROUP/REPOSITORY/...
    -> This shold be DOMAIN/gitlab/GROUP/SUBGROUP/REPOSITORY/...

  • case3
    DOMAIN/gitlab/GROUP/api/v4/..
    -> This should be DOMAIN/gitlab/api/v4/...

Case1 or case2 is found on every repositories.
Case3 is found on only repositories which in the subgroup, and extension may kept loading by this 404.

I couldn't find where these error was triggered.

I'm looking forward to your next version.
Thank you.


I noticed that misunderstanding of GROUP and PROJECT.
Just fixed comment above PROJECT -> GROUP.

Hi @huzisuke ,
Sorry for the delay, tried another fix. Pushed the code to the same branch - tavyandy97-relativeUrl. Could you verify the fix once?

Thank you

Hi @tavyandy97 ,
thanks for new version!

This has one 404 error of requesting DOMAIN/api/v4/...
It should be DOMAIN/gitlab/api/v4/...

I inserted 'gitlab' into axios.js line 6, and this worked perfect!
I tried but couldn't get 'gitlab' as a variable.

I consider this is the last one.
Thank you.

Hi @tavyandy97 ,

I changed axious.js line8 like below, and it worked fine.
baseURL: ${baseUrl}api/v4/projects/,
to
baseURL: ${baseUrl}${fetchURLDetails().dir[0]}/api/v4/projects/\,

However I don't know this is the best solution.
If you'd like to know the value of some variables in my environment, please tell me and I can show you.
Thank you.