microsec [](https://travis-ci.org/pablopunk/microsec)
April 18, 2018 · View on GitHub
Fetch with https all the time
The problem
Sometimes you want to fetch an insecure URL http://insecure-url.com/?example=1 from a secure server https://my-secure-server.com but you get this error:
Mixed Content: The page at 'https://my-secure-server/' was loaded over HTTPS,
but requested an insecure resource 'http://insecure-url.com/'.
This request has been blocked; the content must be served over HTTPS.
The solution
Fetch it with microsec!:
Deploy this microservice and run it with npm start. Let's say you're deployment is on this url: https://secure9000.pro.
// Javascript example
const fetch = require('isomorphic-fetch')
const url = 'https://secure9000.pro/insecure-url.com/?example=1'
fetch(url).then(/* MAGIC */)
Custom headers
The headers you send inside the request will remain intact.
fetch(url, {headers: {'Accept-Language': 'es-ES,es;q=0.8,en;q=0.6,gl;q=0.4'}})
Author
| © 2017 Pablo Varela |