R
Reactiflux

Getting HTML 200 from fetch instead of JSON

Getting HTML 200 from fetch instead of JSON

Gghardin13712/3/2021
did you request json from the backend? not sure if it expects to be told what to return
UUUnknown User12/3/2021
3 Messages Not Public
Sign In & Join Server To View
Gghardin13712/3/2021
oh yeah response.json is going to be a function ok so the backend should never return anything BUT json
UUUnknown User12/3/2021
Message Not Public
Sign In & Join Server To View
Gghardin13712/3/2021
these are on different ports yeah?
UUUnknown User12/3/2021
2 Messages Not Public
Sign In & Join Server To View
Gghardin13712/3/2021
i mean http://localhost:8080 vs http://localhost:8081
UUUnknown User12/3/2021
2 Messages Not Public
Sign In & Join Server To View
Gghardin13712/3/2021
ah so that's one problem
UUUnknown User12/3/2021
Message Not Public
Sign In & Join Server To View
Gghardin13712/3/2021
you're making the request in your frontend, to your front end server
UUUnknown User12/3/2021
Message Not Public
Sign In & Join Server To View
Gghardin13712/3/2021
fetch(`/payment_intents/${paymentIntent.id}/capture`, {
fetch(`/payment_intents/${paymentIntent.id}/capture`, {
says fetch from the same origin i'm on /payment_intents/${paymentIntent.id}/capture
UUUnknown User12/3/2021
Message Not Public
Sign In & Join Server To View
Gghardin13712/3/2021
it doesn't know that your backend is on a different server it only knows what you told it so you'd either want to tell it that and deal with CORS or you'd set up proxying
UUUnknown User12/3/2021
Message Not Public
Sign In & Join Server To View
Gghardin13712/3/2021
well right now it's not it's just giving you the html that would kickstart your front end because it doesn't know what to do with that path
UUUnknown User12/3/2021
3 Messages Not Public
Sign In & Join Server To View
Gghardin13712/3/2021
no absolutely not you're making a request to http://localhost:8080/payment_intents/${paymentIntent.id}/capture your front end server has no idea what to do with that so it's just serving up the base html
UUUnknown User12/3/2021
Message Not Public
Sign In & Join Server To View
Gghardin13712/3/2021
what did you change it do?
UUUnknown User12/3/2021
Message Not Public
Sign In & Join Server To View
Gghardin13712/3/2021
ah ok then yeah that MAY be getting a CORS error
UUUnknown User12/3/2021
3 Messages Not Public
Sign In & Join Server To View
Gghardin13712/3/2021
i don't know if cloudfunctions would let you change the cors headers but possibly
UUUnknown User12/3/2021
Message Not Public
Sign In & Join Server To View
Gghardin13712/3/2021
the browser is telling you it's a cors issue
UUUnknown User12/4/2021
Message Not Public
Sign In & Join Server To View
Gghardin13712/4/2021
are they going to the same place?
UUUnknown User12/4/2021
Message Not Public
Sign In & Join Server To View
Gghardin13712/4/2021
on the same cloudfunction? or different ones?
UUUnknown User12/4/2021
Message Not Public
Sign In & Join Server To View
Gghardin13712/4/2021
hrmm. i don't know a ton about cloudfunctions is it similar to lambda on aws?
UUUnknown User12/4/2021
Message Not Public
Sign In & Join Server To View
Gghardin13712/4/2021
ah ok. so what's in that file? are you applying the cors headers to everything?
UUUnknown User12/4/2021
Message Not Public
Sign In & Join Server To View
Gghardin13712/4/2021
hrmm yeah that ought to work if you open up the network devtools and find the request that isn't working what do you see in the request headers and response headers sections?
UUUnknown User12/4/2021
2 Messages Not Public
Sign In & Join Server To View

Looking for more? Join the community!

R
Reactiflux

Getting HTML 200 from fetch instead of JSON

Join Server