2019-11-24

RxJS Error: CORS is not supported by your browser

rxjs, javascript, devjournal, selfnote

banner

Image by Taco Fleur from Pixabay

This is a note-to-self/devjournal to keep track of the issue I ran into.
Just rephrasing a StackOverflow answer but come back and find easily.

I was playing around with RxJS and ran into following error on

Error: CORS is not supported by your browser

Can reproduce it here

A quick google search returned a StackOverflow question, Using rxjs ajax() I get “CORS is not supported by your browser”.

Ben Lesh(creator of RxJS) replied that one needs to pass a custom XMLHttpRequest object.

1import { XMLHttpRequest } from "xmlhttprequest";2
3function createXHR() {4  return new XMLHttpRequest();5}6
7const ajax$ = ajax({8  createXHR, // <--- here9  url: genURL_chan(179),10  crossDomain: true,11  withCredentials: false,12  method: "POST",13  body: { since: 0, mode: "Messages", msgCount: 5000 },14});

Now the node script below should work w/o an issue.


Image by Taco Fleur from Pixabay