Thirteen consecutive attempts to fetch information have resulted in failure

I've encountered an issue while attempting to fetch data from my .NET Core 7 API. The error message I'm receiving is as follows: *Unhandled Runtime Error Error: fetch failed

Call Stack Object.fetch node:internal/deps/undici/undici (11413:11) process.processTicksAndRejections node:internal/process/task_queues (95:5)*

Here's the code snippet:

import Image from 'next/image'

async function getChamps () {
  const res = await fetch('https://localhost:7046/api/Champion')

  if (!res.ok) { // ! Recommended to handle errors
    throw new Error('Failed to fetch data')
  }

  return res.json() // ? return the data
}

export default async function ListOfChampions () {
  const champions = await getChamps()

  return (
    <ul>
      {champions.map(champ => (
        <li key={champ.champion_id}>
          <Image src={champ.image} alt={champ.name} />
          <p>{champ.name}</p>
        </li>
      ))}
    </ul>
  )
}

When trying to make a GET request to https://localhost:7046/api/Champion using POSTMAN or directly in the browser, it works. However, the fetch operation fails.

Any suggestions on how to resolve this problem?

I have already attempted configuring CORS in my API but with no success.

Answer №1

If you encounter an issue, consider switching from localhost to 127.0.0.1. I faced a similar problem while using Strapi as a backend and resolved it by making this change.

Answer №2

The issue may arise due to an incorrect address. Try restarting the local server to resolve it

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for updating the value of an input text field in one HTML table according to a certain value entered in a different input text field located in another HTML table

I am working with an HTML table that consists of one row. Within this row, there are two TDs which each hold their own tables (each containing 10 rows with 10 input fields). My goal is to update the value of another corresponding text field based on change ...

Trouble with Google Bar Chart's Background Color not Updating

I'm having issues with the background color in my google Material Charts static api library. Despite entering a specific color code, the change is not being reflected when the page loads. These are the options I have set: var options = { b ...

What is the process for retrieving all elements from a LINQ query?

I'm currently in the process of testing the relationships in my database using Entity Framework. I'm facing an issue with retrieving all elements from a LINQ query. The scenario is that I have a table called Web_Profiles which has a many-to-many ...

monitoring the winstonjs logs and inserting additional parameters

Can an argument be injected into a log, like error, debug, or info, using the configuration of winston (createLogger)? I want to intercept the log and include an object in each log entry. ...

Utilize Node.js to sort through data

One API is providing me with this type of response. I need to extract the latitude and longitude of a single entity. How can I filter this data using JavaScript (Node.js)? header { gtfs_realtime_version: "1.0" incrementality: FULL_DATASET timestamp: ...

What is the best way to accurately identify ad blockers and show a warning message?

Our Next.js project includes custom ad slots that are designed to display Google ads or local advertisers' customized ads throughout the site. Our goal is to identify if an ad blocker is obstructing the proper display of these ads, and to provide a wa ...

Nested ng-repeats within ng-repeats

I have a question regarding the correct way to utilize an inner ng-repeat inside of an outer ng-repeat: Essentially, I am looking to implement something along these lines: <tr ng-repeat="milestone in order.milestones"> <td>{{mi ...

Unable to adjust the width of the react-select component

I've been struggling to adjust the width of the select element but no matter what I try, it remains at a default width of about 75px. const CustomContainer = styled('div')` width: 100%; height: 100%; display: flex; flex-flow: row wr ...

Error: The index $_GET[...] is not defined

When transferring a javascript variable to a php file, I encounter an issue where $_GET['something'] keeps returning as an undefined index. Despite this error, the correct result is displayed and written into the xml. However, when I attempt to ...

Exploring the World of Subclassing Arrays in JavaScript: Uncovering the TypeError of Array.prototype.toString's

Can JavaScript Arrays be subclassed and inherited from? I am interested in creating my own custom Array object that not only has all the features of a regular Array but also contains additional properties. My intention is to use myobj instanceof CustomArr ...

Having trouble adjusting the refresh timer based on user focus with setTimeout

For the past few days, I've been utilizing an ajax call to dynamically refresh specific elements of my webapp every 5 seconds. The implementation with setInterval(refreshElements, 5000) worked perfectly fine. However, now I am considering whether the ...

ASP.NET failing to execute Javascript

Can you take a look at this code and help me figure out why the alert is not working on the webpage? The console.WriteLine statement below it is running fine, but the alert isn't appearing. private void PublishLoop() { while (Running ...

Invalid element type. The promise returned is for undefined value. The element type for lazy loading must resolve to a class or function

I'm currently using NextJS v14 alongside MUI v5. On my home page, I have a news component that's causing an error when I try to turn it into a server component for fetching data. Despite successfully logging the data in the terminal, the issue ar ...

activating the button once all fields have been completed

Currently, I am utilizing knockout.js for data binding. There is a form with fields for name, number, email, etc. If any of these fields are left blank and the save button is clicked, the button becomes disabled as expected. However, if I later fill in th ...

Issue: unable to establish a connection to 127.0.0.1:465 to send an email

When attempting to send smtp alert messages from my site's email account <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="55363a3b2134362115383a3b263c21307b363">[email protected]</a> to the email addresses of m ...

Occasionally, the view fails to update following an $http request

Although this question has been posed multiple times before, none of the solutions seem to be effective for my issue. Controller app.controller('HomeController', function ($scope, $timeout, $http) { $scope.eventData = { heading: ...

Is there a way to use AJAX for transferring a value?

I am looking to transmit a value to a php-script (servo.php) that will then write the received data in a file (/dev/servoblaster). The script section of my HTML file (index.html): <script> function tiltt() { var tilt = document.getElementById("tilt ...

Incorporate Stripe's checkout feature seamlessly into your website using Next.js

I am currently working on integrating Stripe payment with an embedded form in my Next.js project. Unfortunately, due to the new addition to Stripe, I am having trouble finding resources on how to accomplish this. The official documentation is available but ...

What steps should be taken to address the Chrome alert stating that the deferred DOM Node cannot be identified as a valid node?

While working on my node.js project hosted on a localhost server, I've encountered an unusual warning message in the inspector. The warning states: The deferred DOM Node could not be resolved to a valid node. Typically, I use the inspector to examine ...

How to open a new window in a separate desktop on macOS using Javascript

I am currently browsing my website on a Mac computer. I am interested in opening a new tab on the second desktop using Mission Control. Is this achievable? If so, could you please guide me on how to do it? After searching extensively online, I have been u ...