Absolute URL

One issue with using isomorphic-fetch is that it currently requires the fetch URLs to be absolute. So we need to update the URL used in the read fetch method, defined in api-media.js, into an absolute URL.

Instead of hardcoding a server address in the code, we will set a config variable in config.js.

mern-mediastream/config/config.js:

serverUrl: process.env.serverUrl || 'http://localhost:3000'

Then we will update the read method in api-media.js to make it use an absolute URL to call the read API on the server.

mern-mediastream/client/media/api-media.js:

import config from '../../config/config'const read = (params) => {  return fetch(config.serverUrl +'/api/media/' + params.mediaId, {    method: 'GET' }).then((response) => { ... }) ...

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.