Create-react-app: making api request failed at github page

Created on 15 Nov 2017  路  2Comments  路  Source: facebook/create-react-app

So i have this api request to themoviedb, everything works fine at first in the local development server and etc. my url for requesting needs api key and such like so :
const URL = 'https://api.themoviedb.org/3/discover/movie?api_key=83XXXXXXXXXXXXXX&language=en-US&sort_by=popularity.desc&include_adult=false&include_video=false&page=1'
But right after I deployed to my github page it does not work, its making api request with the wrong link? like with this url
https://api.themoviedb.org/3/movie/react-mdb?api_key=83XXXXXXXXX&language=en-US

The issues is that i know my homepage in my package.json is http://irfanabliz.github.io/react-mdb for my github page, thats why in the end it changed to movie/react-mdb which causing wrong url fetch, how to fix this? maybe its pretty easy i just can't get my head around this. Thank you very much if anyone know how to fix this !

question

Most helpful comment

Note that you're doing fetch("https://api.themoviedb.org/3/movie/"+this.props.match.params.id+"?api_key=83302bb50aea7923d908bf86d7164f90&language=en-US");

On your site, this.props.match is react-mdb so this is working as expected.
image

Did you use the basename parameter on your router as described in the documentation?

p.s. if that API key is sensitive, I suggest proxying this request behind your server and not exposing it on the front end

All 2 comments

Note that you're doing fetch("https://api.themoviedb.org/3/movie/"+this.props.match.params.id+"?api_key=83302bb50aea7923d908bf86d7164f90&language=en-US");

On your site, this.props.match is react-mdb so this is working as expected.
image

Did you use the basename parameter on your router as described in the documentation?

p.s. if that API key is sensitive, I suggest proxying this request behind your server and not exposing it on the front end

got it, thank you very much, basename router was not there thats why.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dualcnhq picture dualcnhq  路  3Comments

alleroux picture alleroux  路  3Comments

ap13p picture ap13p  路  3Comments

fson picture fson  路  3Comments

alleroux picture alleroux  路  3Comments