#Error while fetching api with different origin

35 messages · Page 1 of 1 (latest)

woven swift
#

I need to fetch some data from an api with a different origin. The data is avalailable on port 3000 and i'm trying to get it on port 3001. But the response i get is null. I think it has to do with cors but i tried a lot of stuff and it didn't work.

#

I can give you the github repos if you need them

keen bear
#

also

#
const req = await fetch(URL).then (res => {
    return res.json ();
})```
woven swift
#

But it works for this guy https://youtu.be/5miHyP6lExg?t=27903

Discord for any problems/errors/bugs: https://www.codewithantonio.com/discord

Github & Live Website: https://www.codewithantonio.com/projects/ecommerce

In this video, we will put a special emphasis on the Next.js 13 App Router, which is the latest addition to the Next.js framework.

The Next.js 13 App Router is a powerful tool that enables you...

▶ Play video
keen bear
woven swift
#

Im not. I'm fecthing from port 3000 which does exist, into the store at 3001

#

Watch the video at that timestamp. That's what i'm trying to do

keen bear
woven swift
#

I can also give the whole github repo

keen bear
#

No

woven swift
#

Ok

keen bear
#

Nevermind, it's ok lol

woven swift
#

I don't think that's where the is issue tho. I think it's response from the fetch. I'm passing the categories which are null, and it's giving me an error because it can't map trought null

keen bear
woven swift
#

are you sure you don't want the whole repo?

keen bear
#

I mean, feel free to send it

woven swift
keen bear
#

Since it can be useful for looking through files without you having to post anything

woven swift
#

ok

#

Well it's there so feel free to access it

keen bear
#

Does the API return something?

woven swift
#

Yes for sure

#

If i go to the url i get this

#

[{"id":"1997d654-c99c-48ab-8aeb-afe7deeb5736","storeId":"97031b30-3c0f-46e5-9ef8-f760012e6f32","billboardId":"6337c632-4266-4b25-b219-9e0e185d2ef3","name":"Glasses","createdAt":"2023-07-23T13:30:43.285Z","updatedAt":"2023-07-23T13:33:38.706Z"},{"id":"19f6cbaf-fc22-4901-92f4-5e148ee89a23","storeId":"97031b30-3c0f-46e5-9ef8-f760012e6f32","billboardId":"eb408522-ecda-4440-9f90-87f2cc04feaa","name":"Shirts","createdAt":"2023-07-22T08:35:30.797Z","updatedAt":"2023-07-22T16:39:47.361Z"},{"id":"226f58bc-f5b3-4bd2-a097-51c7228cbb04","storeId":"97031b30-3c0f-46e5-9ef8-f760012e6f32","billboardId":"88da43c2-f931-4ee1-bba7-329a7fa7147e","name":"Shoes","createdAt":"2023-07-22T08:35:13.440Z","updatedAt":"2023-07-23T08:56:27.122Z"},{"id":"9f05705c-ad6e-4692-9eaf-7f107d97addc","storeId":"97031b30-3c0f-46e5-9ef8-f760012e6f32","billboardId":"183b66d7-f1b1-4cb2-b612-2af074895c37","name":"test","createdAt":"2023-07-27T08:59:42.832Z","updatedAt":"2023-07-27T08:59:42.832Z"}].

keen bear
#

It returns a object[].

#

It can be a problem within your file extension?

#

In the video is get-categories.tsx, while your file extension is just typescript.

#

But this does not seem to be the issue;

woven swift
#

I have a slightly different folder structure. I don't think any of has to do with the issue