Skip to content

Instantly share code, notes, and snippets.

@scrivy
Created July 17, 2016 07:17
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save scrivy/0909468fde8f117a3d66507c8bb3fe12 to your computer and use it in GitHub Desktop.
Save scrivy/0909468fde8f117a3d66507c8bb3fe12 to your computer and use it in GitHub Desktop.
self signed https localhost proxy with golang
copied from https://devcenter.heroku.com/articles/ssl-certificate-self
install go and openssl
mac os x: brew install go openssl
Generate private key and certificate signing request
openssl genrsa -des3 -passout pass:x -out server.pass.key 2048
openssl rsa -passin pass:x -in server.pass.key -out server.key
rm server.pass.key
openssl req -new -key server.key -out server.csr
openssl x509 -req -sha256 -days 365 -in server.csr -signkey server.key -out server.crt
start the proxy
go run httpsproxy.go
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
)
func main() {
localProxyUrl, _ := url.Parse("http://127.0.0.1:8100/")
localProxy := httputil.NewSingleHostReverseProxy(localProxyUrl)
http.Handle("/", localProxy)
log.Println("Serving on localhost:8080")
log.Fatal(http.ListenAndServeTLS(":8080", "server.crt", "server.key", nil))
}
@siliconcow
Copy link

How do you tell ionic run to configure the app to use the proxy?

@ronaiza-cardoso
Copy link

@siliconcow I have this question too, do you have any light about that?

@lolgans
Copy link

lolgans commented Aug 29, 2017

@NinoSkopac
Copy link

worked!

@arun-dev
Copy link

For all want to know how to connect, suppose your app starting in port 8100 ( http://loclhost:8100 ) use https://<your_ipv4_address>:8080/ . for example mine starting in https://192.xx.xx.1x3:8080/

@JorgeAGGVector
Copy link

@lolgans your link it dosent work, anyone can tell me how to run this into ionic app?

@revilon1991
Copy link

I have a problem.
I generate the certificate and put my system as trust.
Change network config with HTTPS proxy for localhost:8080
Follow to any site but my connection was lost.

I saw in logs this text:
2021/03/01 00:45:03 http: TLS handshake error from 127.0.0.1:50751: tls: first record does not look like a TLS handshake

What is wrong?
I was trying with mac and iPhone...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment