From 20f3685d06fd510e0a8fefb9759d8b8b9640c87f Mon Sep 17 00:00:00 2001 From: Fabien Bochu Date: Sun, 20 Aug 2017 21:36:29 +0200 Subject: [PATCH] Use request defined host in index template --- api/api.go | 3 ++- index.html | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/api/api.go b/api/api.go index 996baa8..ca3ce19 100644 --- a/api/api.go +++ b/api/api.go @@ -187,9 +187,10 @@ func (a *API) DefaultHandler(w http.ResponseWriter, r *http.Request) *appError { return internalServerError(err) } var data = struct { + Host string Response Oracle - }{response, a.oracle} + }{r.Host, response, a.oracle} if err := t.Execute(w, &data); err != nil { return internalServerError(err) } diff --git a/index.html b/index.html index 346f804..b70c7f0 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,7 @@ - What is my IP address? — ifconfig.co + What is my IP address? — {{ .Host }} @@ -44,37 +44,37 @@

CLI examples:

-$ curl ifconfig.co
+$ curl {{ .Host }}
 {{ .IP }}
 
-$ http -b ifconfig.co
+$ http -b {{ .Host }}
 {{ .IP }}
 
-$ wget -qO- ifconfig.co
+$ wget -qO- {{ .Host }}
 {{ .IP }}
 
-$ fetch -qo- https://ifconfig.co
+$ fetch -qo- https://{{ .Host }}
 {{ .IP }}
 
-$ bat -print=b ifconfig.co/ip
+$ bat -print=b {{ .Host }}/ip
 {{ .IP }}
{{ if .IsLookupCountryEnabled }}

Country lookup:

-$ http ifconfig.co/country
+$ http {{ .Host }}/country
 {{ .Country }}
{{ end }} {{ if .IsLookupCityEnabled }}

City lookup:

-$ http ifconfig.co/city
+$ http {{ .Host }}/city
 {{ .City }}
{{ end }}

JSON output:

-$ http ifconfig.co/json
+$ http {{ .Host }}/json
 { {{ if .IsLookupCityEnabled }}
     "city": "{{ .City }}",{{ end }}{{ if .IsLookupCountryEnabled }}
     "country": "{{ .Country }}",{{ end }}{{ if .IsLookupAddrEnabled }}
@@ -87,12 +87,12 @@ $ http ifconfig.co/json
         

Plain output:

Always returns the IP address including a trailing newline, regardless of user agent.

-$ http ifconfig.co/ip
+$ http {{ .Host }}/ip
 {{ .IP }}
{{ if .IsLookupPortEnabled }}

Testing port connectivity:

-$ http ifconfig.co/port/8080
+$ http {{ .Host }}/port/8080
 {
     "ip": "{{ .IP }}",
     "port": 8080,