blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
padhibibaswan opened this issue · 4 comments
Code :
import {getClient} from 'azure-devops-extension-api';
import * as SDK from 'azure-devops-extension-sdk';
import {WorkItemTrackingRestClient} from 'azure-devops-extension-api/WorkItemTracking';
import { GitRestClient } from "azure-devops-extension-api/Git/GitClient";
SDK.init().then(() => {
SDK.ready().then(async () => {
// This works perfectly fine and get 200 response code
const client = getClient(WorkItemTrackingRestClient);
const recent = await client.getRecentActivityData();
console.log(recent);
// This does not work and i get the 401 error code.
const gitclient = getClient(GitRestClient);
const repos = await gitclient.getRepositories("projectname");
console.log(repos);
}
);
});
The complete error message that i get is :
Access to fetch at 'https://dev.azure.com///_apis/git/Repositories' from origin 'https://bibasample.gallerycdn.vsassets.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
I have also added the Scope as below :
"scopes": [
"vso.code_write",
"vso.release",
"vso.tokens"
]
Added the scope in correct file and it worked .