Send a http request via proxy which supported by _redirects, but still "the content must be served over HTTPS"

Website

website: https://esgtool-extention.netlify.app/

Problem Description

Due to no https support, I must post a http request to API on http://www.esgcraftgame.com/api.php/. I find that it is not allowed. After seaching, the only way is to add a proxy by _redirects file. But I still failed, and the request return following. It seen has used the proxy, but still failed.

Mixed Content: The page at 'https://esgtool-extention.netlify.app/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://www.esgcraftgame.com/api.php/user/login/index'. This request has been blocked; the content must be served over HTTPS.

Can you please help me?

My Config

  1. _redirects file
/esg/api/*  http://www.esgcraftgame.com/api.php/:splat
/baidu/*  https://www.baidu.com/:splat
  1. post request on “测试按钮” button

      var FormData = require('form-data');
      var data = new FormData();
      data.append('app_key', '123456789');
      data.append('token', '');
      data.append('address', this.address);

      var config = {
        method: 'post',
        url: '/esg/api/user/login/index',
        data: data
      };

      console.log("测试按钮结果")
      console.log(config);
      const token = axios(config)
          .then(function (response) {
            console.log(response);
            return response;
          })
          .catch(function (error) {
            console.log(error);
          });
      return token;
    }

  1. Error
esgtool-extention.netlify.app/:1 Mixed Content: The page at 'https://esgtool-extention.netlify.app/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://www.esgcraftgame.com/api.php/user/login/index'. This request has been blocked; the content must be served over HTTPS.

Hey @XDcat

This would work, however this is not what I see in the live site. Rather, in the app.0e737f40.js file I see

var r = {
  method:"post",
  url:"http://www.esgcraftgame.com/api.php/user/login/index",
  data:o
};

This means you are not using the rewrite proxy you have configured in the _redirects file.

Also, you will need to add a 200 status code otherwise it will default to a 301 redirect, i.e.

/esg/api/*  http://www.esgcraftgame.com/api.php/:splat  200
1 Like

After changing as

/esg/api/*  http://www.esgcraftgame.com/api.php/:splat  200

It’s working now.

Thanks!