/
noaa.go
44 lines (34 loc) · 911 Bytes
/
noaa.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package noaa
import (
"io"
"net/http"
"net/http/httputil"
"net/url"
)
var upstream *url.URL
func init() {
// Manually resolved CNAME of tgftp.nws.noaa.gov
u, err := url.Parse("https://tgftp.cp.ncep.noaa.gov")
if err != nil {
panic("Couldn't parse url: " + err.Error())
}
upstream = u
}
/*
Proxy creates a proxy for https://tgftp.nws.noaa.gov, but http, and listening on
9090. This is because Ubuntu 18.04 ships with [taffybar]() 0.4.6, which only
supports http for the weather widgets and has hardcoded URLs.
To install, add this line to your hosts file:
```
127.0.0.1 tgftp.nws.noaa.gov
```
And run this iptables command:
```
iptables -t nat -A OUTPUT -o lo -p tcp --dport 80 -j REDIRECT --to-port 9090
```
Command: noaa-proxy
*/
func Proxy(_ []string, _ io.Reader) error {
http.Handle("/", httputil.NewSingleHostReverseProxy(upstream))
return http.ListenAndServe(":9090", nil)
}