ContentAPI error: XMLHttpRequest not found

Hi all,

I’m using the contentAPI within After.js, and on SSR it throws

ReferenceError: XMLHttpRequest is not defined
    at dispatchXhrRequest (/node_modules/@tryghost/content-api/es/content-api.js:2268:1)
    at new Promise (<anonymous>)
    at xhrAdapter (/build/webpack:/node_modules/@tryghost/content-api/es/content-api.js:2260:1)
    at dispatchRequest (/build/webpack:/node_modules/@tryghost/content-api/es/content-api.js:2594:1)

EDIT: Fixed! Just do this in the file that does the SSR:

import { XMLHttpRequest } from 'xmlhttprequest-ssl';    
global.XMLHttpRequest = XMLHttpRequest; 
1 Like