|
@@ -9,6 +9,7 @@ import (
|
|
|
"ngrok/log"
|
|
|
"ngrok/msg"
|
|
|
"ngrok/version"
|
|
|
+ "os"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"sync/atomic"
|
|
@@ -107,10 +108,20 @@ func newTunnel(m *msg.RegMsg, ctl *Control) (t *Tunnel) {
|
|
|
go t.listenTcp(t.listener)
|
|
|
|
|
|
case "http":
|
|
|
+ vhost := os.Getenv("VHOST")
|
|
|
+ if vhost == "" {
|
|
|
+ vhost = fmt.Sprintf("%s:%d", domain, publicPort)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Canonicalize virtual host on default port 80
|
|
|
+ if strings.HasSuffix(vhost, ":80") {
|
|
|
+ vhost = vhost[0 : len(vhost)-3]
|
|
|
+ }
|
|
|
+
|
|
|
if strings.TrimSpace(t.regMsg.Hostname) != "" {
|
|
|
t.url = fmt.Sprintf("http://%s", t.regMsg.Hostname)
|
|
|
} else if strings.TrimSpace(t.regMsg.Subdomain) != "" {
|
|
|
- t.url = fmt.Sprintf("http://%s.%s", t.regMsg.Subdomain, domain)
|
|
|
+ t.url = fmt.Sprintf("http://%s.%s", t.regMsg.Subdomain, vhost)
|
|
|
}
|
|
|
|
|
|
if t.url != "" {
|
|
@@ -120,7 +131,7 @@ func newTunnel(m *msg.RegMsg, ctl *Control) (t *Tunnel) {
|
|
|
}
|
|
|
} else {
|
|
|
t.url, err = tunnels.RegisterRepeat(func() string {
|
|
|
- return fmt.Sprintf("http://%x.%s", rand.Int31(), domain)
|
|
|
+ return fmt.Sprintf("http://%x.%s", rand.Int31(), vhost)
|
|
|
}, t)
|
|
|
|
|
|
if err != nil {
|
|
@@ -145,7 +156,6 @@ func newTunnel(m *msg.RegMsg, ctl *Control) (t *Tunnel) {
|
|
|
t.Info("Registered new tunnel")
|
|
|
t.ctl.out <- &msg.RegAckMsg{
|
|
|
Url: t.url,
|
|
|
- Port: publicPort,
|
|
|
ProxyAddr: fmt.Sprintf("%s", proxyAddr),
|
|
|
Version: version.Proto,
|
|
|
MmVersion: version.MajorMinor(),
|