Use basic fetch

useEffect(async () => {
    fetchData();
}, []);

const fetchData = async () => {
    try {
      const response = await fetch('https://api.npms.io/v2/search?q=react');
      if (!response.ok) {
        throw new Error('Network response was not ok');
      }
      const result = await response.json();

      setData(result);
    } catch (error) {
      console.error('Error fetching data:', error.message);
    }
  };

Hello, when i want use fetch i stable received answer ‘Refused to connect to ‘***’ because it violates the following Content Security Policy directive: "connect-src ‘self’ ****’ What this problem and how to decide?

1 Like

Did you declare external hosts in the forge manifest?

I added to manifest:

permissions:
  scopes:
    - manage:jira-configuration
    - read:jira-user
    - read:jira-work
    - write:jira-work
  content:
    styles:
      - 'unsafe-inline'
  external:
    fetch:
        backend:
          - 'https://api.npms.io'

It looks like you are making that call from the front-end, if that is the case maybe you should use client instead of backend in the manifest.

1 Like

Thank anybody, the issue solved