0

I would like to access the raw files in a repository of mine that is on gitlab through an ajax request. However, it's not working, I'm wondering if I have to setup my project accordingly or something. Obviously my project is public. This is the error message I get :

No 'Access-Control-Allow-Origin' header is present on the requested resource.

Which means it's on their end.

Ced
  • 15,847
  • 14
  • 87
  • 146

1 Answers1

0

To understand Access-Control-Allow-Origin header, I highly recommend How does Access-Control-Allow-Origin header work?

When Site A tries to fetch content from Site B, Site B can send an Access-Control-Allow-Origin response header to tell the browser that the content of this page is accessible to certain origins. (An origin is a domain, plus a scheme and port number.) By default, Site B's pages are not accessible to any other origin; using the Access-Control-Allow-Origin header opens a door for cross-origin access by specific requesting origins.

If your GitLab is hosted on gitlab.com, I don't see a way to add your domain to response header.

The easiest solution is wrapping XMLHttpRequests to GitLab in requests to your application - and on the backend you will simply fetch and return data. For example, you won't send a XML request to https://gitlab.com/pdaw/test/raw/master/README.md, but tohttps://my.app.com/fetch-file?file=pdaw/test/raw/master/README.md. On the backend of the fetch-file action you will fetch and return raw data from https://gitlab.com/pdaw/test/raw/master/README.md

Community
  • 1
  • 1
Piotr Dawidiuk
  • 2,961
  • 1
  • 24
  • 33
  • That's why I said it was on their end. Maybe if I change a setting on my gitlab account or smtg they add the header automatically. Thanks anyway... It seems pretty weird that they don't allow it tbh. I don't wanna go through their api just to do that – Ced Jan 11 '17 at 21:06
  • @Ced As I see, this problem is nagging, https://gitlab.com/gitlab-org/gitlab-ce/issues/24596 for example – Piotr Dawidiuk Jan 11 '17 at 21:14