andrewnjoo / Movie-App

Full stack web application built with React | Vite | Express | TMDB API
https://movie-app-adnjoo.vercel.app/
MIT License
0 stars 1 forks source link

bug: CORS? error #8

Closed adnjoo closed 1 year ago

adnjoo commented 1 year ago

Description

tv page not loading (redux toolkit query)

https://api.themoviedb.org/3/discover/tv?api_key=${tmdbKey}&include_adult=false&language=en-US&page=1&with_origin_country=US

chrome dev tools console tab Screenshot 2023-05-29 at 8 09 07 AM

chrome dev tools network tab Screenshot 2023-05-29 at 8 16 52 AM

but movies is ok

Investigation

axios was able to retrieve the results..

Screenshot 2023-05-29 at 8 05 34 AM

adnjoo commented 1 year ago

Status Code: 301 (Moved Permanently)

Response Headers:

Location: http://api.themoviedb.org/3/discover/tv?api_key=7aa9ec6612579e4bfd39288619de239c&include_adult=false&language=en-US&page=1&with_origin_country=US

it's redirecting the https request to a http link which Vercel/Vite doesn't allow

adnjoo commented 1 year ago

the problem was a trailing slash in the TV query

        `discover/tv/?api_key=${tmdbKey}&include_adult=false&with_origin_country=US&language=en-US&page=${String(
          page
        )}`,

after

      query: (page = 1) =>
        `discover/tv?api_key=${tmdbKey}&include_adult=false&with_origin_country=US&language=en-US&page=${String(
          page
        )}`,

I guess the TMDB API thinks the request we send is not formatted properly, so it 301 redirects? or something like that..

Reference

TMDB talk