aboutsummaryrefslogtreecommitdiffstats
path: root/gopherproxy.go
diff options
context:
space:
mode:
authorFeuerfuchs <git@feuerfuchs.dev>2019-06-05 13:52:59 +0200
committerFeuerfuchs <git@feuerfuchs.dev>2019-06-05 13:52:59 +0200
commitc55e859bd93016f7246ea62984f7eaa02a325736 (patch)
treee4729c569fb905f069ed8520f7dfce6cf280d10a /gopherproxy.go
parentFix selection color in Chrome (diff)
downloadgopherproxy-c55e859bd93016f7246ea62984f7eaa02a325736.tar.gz
gopherproxy-c55e859bd93016f7246ea62984f7eaa02a325736.tar.bz2
gopherproxy-c55e859bd93016f7246ea62984f7eaa02a325736.zip
Updated font handling
Diffstat (limited to 'gopherproxy.go')
-rw-r--r--gopherproxy.go27
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
19type Item struct { 21type Item struct {
@@ -164,6 +166,23 @@ func RobotsTxtHandler(robotstxtdata []byte) http.HandlerFunc {
164 } 166 }
165} 167}
166 168
169func 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}