diff options
Diffstat (limited to 'gopherproxy.go')
-rw-r--r-- | gopherproxy.go | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/gopherproxy.go b/gopherproxy.go index dc849d0..82215c5 100644 --- a/gopherproxy.go +++ b/gopherproxy.go | |||
@@ -14,6 +14,8 @@ import ( | |||
14 | "github.com/temoto/robotstxt" | 14 | "github.com/temoto/robotstxt" |
15 | 15 | ||
16 | "github.com/prologic/go-gopher" | 16 | "github.com/prologic/go-gopher" |
17 | |||
18 | "github.com/gobuffalo/packr" | ||
17 | ) | 19 | ) |
18 | 20 | ||
19 | type Item struct { | 21 | type Item struct { |
@@ -164,6 +166,23 @@ func RobotsTxtHandler(robotstxtdata []byte) http.HandlerFunc { | |||
164 | } | 166 | } |
165 | } | 167 | } |
166 | 168 | ||
169 | func FontHandler(woff2 bool, fontdata []byte) http.HandlerFunc { | ||
170 | return func(w http.ResponseWriter, req *http.Request) { | ||
171 | if fontdata == nil { | ||
172 | http.Error(w, "Not Found", http.StatusNotFound) | ||
173 | return | ||
174 | } | ||
175 | |||
176 | if woff2 { | ||
177 | w.Header().Set("Content-Type", "font/woff2") | ||
178 | } else { | ||
179 | w.Header().Set("Content-Type", "font/woff") | ||
180 | } | ||
181 | |||
182 | w.Write(fontdata) | ||
183 | } | ||
184 | } | ||
185 | |||
167 | // ListenAndServe creates a listening HTTP server bound to | 186 | // ListenAndServe creates a listening HTTP server bound to |
168 | // the interface specified by bind and sets up a Gopher to HTTP | 187 | // the interface specified by bind and sets up a Gopher to HTTP |
169 | // proxy proxying requests as requested and by default will prozy | 188 | // proxy proxying requests as requested and by default will prozy |
@@ -194,6 +213,10 @@ func ListenAndServe(bind, robotsfile, uri string) error { | |||
194 | styletext = string(styledata) | 213 | styletext = string(styledata) |
195 | } | 214 | } |
196 | 215 | ||
216 | box := packr.NewBox("./assets") | ||
217 | fontdataw, err := box.Find("iosevka-term-ss03-regular.woff") | ||
218 | fontdataw2, err := box.Find("iosevka-term-ss03-regular.woff2") | ||
219 | |||
197 | tpldata, err := ioutil.ReadFile(".template") | 220 | tpldata, err := ioutil.ReadFile(".template") |
198 | if err == nil { | 221 | if err == nil { |
199 | tpltext = string(tpldata) | 222 | tpltext = string(tpldata) |
@@ -212,7 +235,9 @@ func ListenAndServe(bind, robotsfile, uri string) error { | |||
212 | 235 | ||
213 | http.HandleFunc("/", GopherHandler(tpl, robotsdata, styletext, uri)) | 236 | http.HandleFunc("/", GopherHandler(tpl, robotsdata, styletext, uri)) |
214 | http.HandleFunc("/robots.txt", RobotsTxtHandler(robotstxtdata)) | 237 | http.HandleFunc("/robots.txt", RobotsTxtHandler(robotstxtdata)) |
215 | // http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("assets/")))) | 238 | http.HandleFunc("/iosevka-term-ss03-regular.woff", FontHandler(false, fontdataw)) |
239 | http.HandleFunc("/iosevka-term-ss03-regular.woff2", FontHandler(true, fontdataw2)) | ||
240 | //http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("assets/")))) | ||
216 | 241 | ||
217 | return http.ListenAndServe(bind, nil) | 242 | return http.ListenAndServe(bind, nil) |
218 | } | 243 | } |