英文:
Request forbidden while fetching feature flag from gitlab to react application
问题
我在GitLab中创建了一个特性标志。我需要在我的React应用程序中获取该特定标志的值。我编写了以下代码,但该代码生成了403禁止错误。我还检查了个人访问令牌的权限,但仍然显示为禁止。
import axios from 'axios';
const fetchData = async () => {
const response = await axios.get('https://gitlab.com/api/v4/features', {
headers: {
'PRIVATE-TOKEN': '<MY_PERSONAL_ACCESS_TOKEN_HERE>',
},
});
return response.data;
};
useEffect(() => {
console.log(fetchData());
}, []);
我尝试通过Postman访问API,但仍然生成403禁止错误。
英文:
I have created a feature flag in gitlab. I need to fetch the value of that particular flag in my React application. I have written the below code, and the code generates the 403 Forbidden error. I have also checked the permission to the personal access token but still it says forbidden.
import axios from 'axios';
const data = async () => {
const response = await axios.get('https://gitlab.com/api/v4/features', {
headers: {
'PRIVATE-TOKEN': '<MY_PERSONAL_ACCESS_TOKEN_HERE>',
},
});
return response.data;
};
useEffect(() => {
console.log(data());
}, []);
I tried hitting the API through postman but still it results in generating the 403 forbidden error.
答案1
得分: 1
为了在GitLab中与前端SDK一起使用功能标志,您需要使用Unleash代理。
https://github.com/Unleash/unleash-proxy
祝好运!
英文:
In order to use feature flags in gitlab together with a frontend SDK you will need to use the Unleash Proxy.
https://github.com/Unleash/unleash-proxy
Good luck!
答案2
得分: 0
也许您需要验证 Gitlab 中的 CORS 配置。检查您的 GitLab 实例是否已正确配置 CORS(跨源资源共享),以允许来自您的 React 应用程序域的请求。如果 CORS 没有正确设置,可能会导致"403 禁止访问"错误。
英文:
Maybe you need to verify CORS configuration in Gitlab.Check if your GitLab instance has CORS (Cross-Origin Resource Sharing) properly configured to allow requests from your React application's domain. If CORS is not set up correctly, it can result in a "403 Forbidden" error.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论