Request forbidden while fetching feature flag from gitlab to react application

huangapple go评论62阅读模式
英文:

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 &#39;axios&#39;;

const data = async () =&gt; {
    const response = await axios.get(&#39;https://gitlab.com/api/v4/features&#39;, {
      headers: {
        &#39;PRIVATE-TOKEN&#39;: &#39;&lt;MY_PERSONAL_ACCESS_TOKEN_HERE&gt;&#39;,
      },
    });
    return response.data;
  };
  useEffect(() =&gt; {
    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.

huangapple
  • 本文由 发表于 2023年6月6日 14:43:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76412054.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定