Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The subdirectory path issue in Gitlab API URL #90

Open
puff-tw opened this issue Apr 20, 2023 · 7 comments · May be fixed by #92
Open

The subdirectory path issue in Gitlab API URL #90

puff-tw opened this issue Apr 20, 2023 · 7 comments · May be fixed by #92

Comments

@puff-tw
Copy link

puff-tw commented Apr 20, 2023

I noticed a 404 error because the Extension was using an incorrect API URL. This is because my Gitlab installation is located in a subdirectory, like this: https://SITE_DOMAIN/gitlab/.

The incorrect URL was:
https://SITE_DOMAIN/api/v4/projects/123/repository/tree?per_page=10000&ref=master

The correct URL is:
https://SITE_DOMAIN/gitlab/api/v4/projects/123/repository/tree?per_page=10000&ref=master

Since Gitlab is installed in a subdirectory, the correct URL needs to include the subdirectory path (/gitlab/) before the api endpoint.

Is it possible to configure the API URL on the Extension itself?

2023-04-21 02_28_44-Window

@tavyandy97
Copy link
Owner

Hey @puff-tw!
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/.

Furthermore I have tried working out a solution where the extension could pickup the relative URL from GitLab itself, but found no luck there. (Was reported by @huzisuke in #77 but closed it due to no feasible solution)

@tavyandy97
Copy link
Owner

The solution you are recommending is that we have a custom field where we can punch in the relative URL? Where do you recommend we put the option?

One possible place I could figure out would be the extension popup -
image

@puff-tw
Copy link
Author

puff-tw commented Apr 23, 2023

The solution you are recommending is that we have a custom field where we can punch in the relative URL? Where do you recommend we put the option?

One possible place I could figure out would be the extension popup - image

That sounds like a feasible approach. Placing the option in the extension popup could work well.

@tavyandy97
Copy link
Owner

I'll try working on that in this week, will keep you updated on this issue 😄

Thanks for requesting the feature and helping making SpanTree a better extension 🌳

@yurenchen000
Copy link

A. site url detect

Was reported by @huzisuke in #77 but closed it due to no feasible solution

on gitlab page it has global variable gon
// tested on gitlab-ce 11.4.5, gitlab 14.4.1-ee

> gon.gitlab_url
'https://demo-site.com/gitlab'
> gon.relative_url_root
'/gitlab'

gitlab_site_url-

is this info enough for api url detect?
@tavyandy97


B. ui setting item

One possible place I could figure out would be the extension popup

if it have to leave a setting entry on GUI,
is it possible to place it at the span-tree main-panel,
which is easier to reach than extention icon (normal collapsed) menu

spantree_setting-

(like the octotree setting icon)
octotree_setting-

@yurenchen000
Copy link

yurenchen000 commented Jul 10, 2023

rough verify code

seems chrome extension js can't directly access page global variable.
I'm not familar with extension delelop, I just did a rough workaround to verify feasibility:

// it's based on content.js (from 0.0.5.0 extension dir) , formated by chrome F12

+var base_url = (document.head.innerHTML.match(/;gon.gitlab_url="(.*?)";/) || [,window.location.origin])[1];
+console.log('---spantree:', base_url);
var r = t(9669)
  , i = t.n(r)
  , o = t(3955);
const a = {
-   baseURL: `${window.location.origin}/api/v4/projects/`
+   baseURL: `${base_url}/api/v4/projects/`
}                                                                                                          

it works ( via chrome load unpacked modified extension dir )

TODO: check URI to defense injection


src maybe correspond here
https://github.com/tavyandy97/span-tree/blob/v0.0.4.2/event/axios.js#L4

@yurenchen000
Copy link

yurenchen000 commented Jul 12, 2023

I send a PR here
#92

@tavyandy97

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 a pull request may close this issue.

3 participants