Ionic CORS inconsistency between android build and development environment

Hello guys!

I m pretty new to ionic and I m currently trying to make an app where you can get the link to the audio of the youtube video, it looks good on paper until i tried it out. I know there is a problem regarding with CORS so i tried to use cor-anywhere heroku (a cor proxy). e.g-> to get the data. It works fine but the only problem is sometimes it takes as much as 2 minutes to get what i want which is not ideal. So I made a nodejs web application and put it on my web hosting. (I also set the response header of the application to “Access-Control-Allow-Origin” to *) and then, it works well! Yay! But here comes the actual problerm.

The android build can’t seem to access my nodejs application despite it worked well in the localhost:8100 (development env), Umm to be more clear, e.g -> this is my link ->

let res = Http.request({
method: ‘GET’,
url: '’+this.YoutubeID,


And it didnt work.

So again, I changed it to‘mylink’ and it works well. So what is wrong with my code? Please do answer. If the information is not enough please do tell me


One thing would appear to be that you wrote “htto” where you meant “http”.

1 Like

That’s just my typo here, it is http in my actual code

here is my code on my server, in case you want to know

const Fetch = require("node-fetch");
var http = require('http');
const url = require('url');

const port = process.env.PORT || 3000

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    const queryObject = url.parse(req.url,true).query;
    // YouTube video ID
    var videoID =;

        // Fetch video info
        Fetch("" + videoID).then(response => {
            if (response.ok) {
                response.text().then(yData => {
                 // parse response to find audio info
                 var ytData = parse_str(yData);
                  var getAdaptiveFormats = JSON.parse(ytData.player_response).streamingData.adaptiveFormats;
                var findAudioInfo = getAdaptiveFormats.findIndex(obj => obj.audioQuality);
                 audioURL = getAdaptiveFormats[findAudioInfo].url;
    console.log("server started!");

function parse_str(str) {
  return str.split('&').reduce(function(params, param) {
    var paramSplit = param.split('=').map(function(value) {
      return decodeURIComponent(value.replace('+', ' '));
    params[paramSplit[0]] = paramSplit[1];
    return params;
  }, {});

and this is my http code on the client side

let res = Http.request({
              method: 'GET',
              url: ''+this.YoutubeID,
               //ofc this is not my actual domain but just an example
            res.then(responseData => {

               //this is my service for presenting toast to show the details to the user
              this.service.fileService.presentToast(, 10000);
            }, reason => {
              this.service.fileService.presentToast(reason, 10000);