Access to a local host with a self-signed certificate through https using Ajax

I am working on a NodeJS application that runs a server on https://localhost:portand uses a self-signed certificate (since no provider provides a certificate for localhost). I use the AJAX call from my site to get into locahost and send data to the NodeJs application. My calls are being blocked due to the INSECURE_CONTENT, which is expected. I want to know if we have workarounds for this?

+4
source share
4 answers

( see update below )

- . AJAX.

Chrome

Firefox

  • localhost firefox. .
  • ""
  • ...
  • ,
  • , " "
  • " ". . .

    • enter image description here
    • enter image description here

UPDATE:

op, :

( ) proxy node. , http://localhost/proxy?yourwebsites_api/getData. node - GET URL- -. . c# HttpWebRequest HttpClient PHP curl.

+5

local.host 127.0.0.1 , local.host 127.0.0.1 ( )
local.host, nodejs, , .
local.host, .

:

openssl req -x509 -nodes -days 1000 -subj '/C=US/ST=CA/L=MV/CN=local.host'  -newkey rsa:2048 -keyout local.host.key -out local.host.crt

osx hosts /etc/hosts c:\windows\system32\drivers\etc\hosts

:

OSX:
https://pubs.vmware.com/flex-1/index.jsp?topic=%2Fcom.vmware.horizon.flex.admin.doc%2FGUID-9201A917-D476-40EF-B1F4-BBF14AB83D94.html


http://www.thewindowsclub.com/manage-trusted-root-certificates-windows

Update:

Op OP, .

myapp.mydomain.com , 127.0.0.1 . , . , , , , . .

. , . , , charlesproxy.

+3

- ngrok. Ngrok wildcardcerts, , URL- https://mycompany.ngrok.io

, (URL- ) ngrok (, , ngrok , )

Ngrok is also great if you want to share your work. The tunnels created by ngrok are open to the public (unless you are password protected)

This is $ 60 per year for your own domain. Free if you want to use random domains like https://ba615d46.ngrok.io

0
source

Firstly, you have not provided any code. Is this an Express app? If so, this may help.

import express from 'express'
const app = express()

app.enable('trust proxy')

app.use((request, response, next) => {
  if (this.request.headers['x-forwarded-proto'] !== 'https') {
    return response.redirect(`https://${request.headers.host}${request.url}`)
  }
  return next()
})

const server = app.listen(process.env.port || 5000, function() {
  console.log('Server running at http://0.0.0.0:' + server.address().port)
})
<div id="output"></div>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<script type="text/babel">
const getMessage = () => "Hello World";
document.getElementById('output').innerHTML = getMessage();
</script>
Run codeHide result
0
source

Source: https://habr.com/ru/post/1684710/


All Articles