Requesting an HTTP resource from HTTPS Website (again)

Hello everyone, I am experiencing an issue that has been solved on here but i am unfamiliar with the syntax and usage of the redirects. I have an endpoint that i am using for my app that is http based and get the classic “Chrome: Mixed Content: The page at ‘’ was loaded over HTTPS, but requested an insecure resource ‘’. This request has been blocked; the content must be served over HTTPS.”

I understand this is due to the endpoint being served over HTTP, and not HTTPS which causes an issue in mixed content. My issue is implementing the solution kindly answered here Requesting an HTTP resource from HTTPS Website

Where exactly do i implement the redirect? Do i have to make a toml file? My endpoint in axios is ‘http://webservices.nextbus.com/service/publicJSONFeed’, the solution that was posted above mentioned to use this /* http://webservices.nextbus.com/service/:splat 200 in the redirect rule.

I have no idea where to place the rule, and lets say i did implement the rule would it look like this "/* http://webservices.nextbus.com/service/publicJSONFeed:splat 200? Im just very unsure and would hope someone could point me in the right direction. Thanks so much for your time!

@hector4213 Welcome to the Netlify community.

That particular code must reside in a _redirects file in the top level of your website.

You can also translate it and add it to your netlify.toml file, the easiest way of doing so would be to use the Play page. Plug in your redirects code, and out will come your .toml equivalent.

https://play.netlify.com/redirects

Thanks for your kind reply!

I made a netlify.toml file in my project, this is what i have so far…I have a feeling i am entering something incorrectly as i still get the cors error in my console.

[[redirects]]
from = “http://webservices.nextbus.com/service/publicJSONFeed
to = “/* http://webservices.nextbus.com/service/publicJSONFeed:splat 200”
status = 200
force = true

Could it be the URL i am entering that is incorrec?, my baseURL for my api endpoint is the “from” parameter of the redirect in my toml file.

@hector4213 Even without knowing the details, it would seem that the redirect should look more like this:

[[redirects]]
from = “http://webservices.nextbus.com/service/publicJSONFeed/*”
to = “http://webservices.nextbus.com/service/publicJSONFeed:splat”
status = 200
force = true

As far as I can tell, we don’t host webservices.nextbus.com so our redirects wouldn’t have any impact on that traffic. We also won’t ever accept an HTTP connection without redirecting it to HTTPS before applying redirects, as far as I know.

I think you’d want something more like this as a redirect:

[[redirects]]
from = "/path-at-netlify"
to = "http://webservices.nextbus.com/service/publicJSONFeed"
status = 200
force = true

This lets us accept the request as https://yournetlifysite/path-at-netlify and then makes an http connection to your endpoint silently - the browser won’t know what we do “behind the curtain”. :slight_smile:

Thanks for your help @fool but i still get the same error. Perhaps I am not providing enough background information or probably incorrect information. I have to apologise for the trouble. Perhaps you could look at my code? if thats not too much trouble? I am a beginner developer who is self-learning and hopefully gain entry as a front end web developer, but this CORS issue is going to give me a stroke!

howdy hector, just a heads up that fool is out on PTO this week but back next week.

Question: is there any way to get the endpoint to run over https instead?

Thanks @perry for the update, got a little sad when I had no reply. I appreciate the support it really distinguishes netlify from other service. The community is so helpful, especially through my noob struggles.

of course! we do try and provide some answer to everyone who writes in, but with only 8 of us to take care of hundreds of thousands of free customers (and enterprise businesses who pay us a lot!) it can get too busy sometimes and we get delayed. But i bet we can find a solution to your problem soon, and thanks for the kind words.

We’ve tried really hard to make our support forums kind & friendly to everyone, we don’t think it is helpful when people are too intimidated to ask questions because they are new!

i wonder if @jonsully has any thoughts on this? he’s usually full of good advice!

1 Like

Hi Friends! :wave:t2:

@hector4213 if the question is “Is it possible to use Netlify as a proxy service to mask that an underlying service isn’t served over HTTPS yet” the answer is yes… with caveats. My first question would be the same as @fool’s - Netlify’s redirects service is made to work for sites that are hosted on Netlify. Is your site hosted on Netlify? Or are you just wanting to use Netlify as a total stand-alone proxy?


Jon

Welcome back @perry :slight_smile:

1 Like

Yes. The app is hosted on netlify. https://6ixbus.netlify.app

Oh I see.

http://webservices.nextbus.com/service/publicJSONFeed is the HTTP data feed that’s blocked. Easy peasy!

It looks like you prefer the netlify.toml file format instead of _redirects - here’s what you’ll want:

[[redirects]]
  from = "/feed/*"
  to = "http://webservices.nextbus.com/service/:splat"
  status = 200
  force = true

So once you have that, instead of having the javascript on your page reach out to http://webservices.nextbus.com/service/publicJSONFeed, just have it reach out to /feed/publicJSONFeed (an absolute path on your own domain) and it should work perfectly well.

What’s happening is that the redirect from option will intercept any request going to https://6ixbus.netlify.app/feed/______ and, because we use a status = 200 aka a rewrite - the Netlify node that’s handling the redirect will reach out to the target (http://webservices.nextbus.com/service/______) then pass the result back to the caller directly, not through a 301 or 302 -style redirect. It’s faking as if your site has that data on that feed/______ path of its own :100: super powerful concept and tool from Netlify!

Let me know if that works :slight_smile:


Jon

1 Like

Thanks, ill get to work on changing that and i will let you know how it goes! I appreciate all the help.

@jonsully Thanks so much for all your help! It works beautifully! I’m elated. I’m trying to learn everything on my own to become a web dev and I appreciate the community for their many attempts at helping me with my problem. Thanks everyone from @perry and fool. I would of never imagined people being so helpful, I should stop hanging out on stack overflow. Anyways my apps works beautifully and I can’t stress enough how much this means to me. Thanks for the bottom of my heart. Hope to use netlify again for my other React Projects.

2 Likes