2

My requirement is fetching data from gitlab file through Angular application . We don't have any back end service to provide data. I have to get data directly from gitlab file. So I wrote below code.

private _jsonURL = 'gitlabpath/appdata.json';
constructor(private _Activatedroute: ActivatedRoute, private http: HttpClient, private rd: Renderer2) {
this.getJSON().subscribe(data => {
  this.objJs = data;
});}
public getJSON(): Observable<any> {
const headers = new HttpHeaders({})
return this.http.get(this._jsonURL, {headers});}

But I am getting the following error

*

has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

*

Please help me to fix this issue.

I didn't see any example for accessing gitlab file from angular code anywhare.

GRVPrasad
  • 1,228
  • 1
  • 9
  • 24
sarath
  • 3,181
  • 7
  • 36
  • 58

1 Answers1

2

It seems that Gitlab is CORS blocked, except for their own domains. You probably calling it from localhost or another url which they do not support. You could try and make a backend system which acts as a proxy to retrieve the data, or you could use an existing one such as 'cors-anywhere'

For example: https://cors-anywhere.herokuapp.com/https://your-lab-url-here.com

There is a similar question on StackOverflow with a better explanation, you can find it here.

Alternatively you could try and use the Gitlab API endpoint to see if you can retrieve your data that way, see: https://docs.gitlab.com/ee/api/

Mikey123
  • 1,201
  • 2
  • 12
  • 23
  • we don't have any back end system. So what shall I do? – sarath Feb 07 '20 at 13:31
  • You could try and use the second option in my reply, prefix your gitlab url with ' https://cors-anywhere.herokuapp.com/' to use that as a proxy. Keep in mind though this is not an ideal solution. Have you tried looking into the Gitlab api to see if they have endpoints that could suit your needs? See: https://docs.gitlab.com/ee/api/ – Mikey123 Feb 07 '20 at 13:37