~sotirisp/kindleto

395428d7247bb365236c5b9ea271b9936ab396a6 — Sotiris Papatheodorou 1 year, 10 months ago f0cfba9
Handle homepage like any other page
1 files changed, 14 insertions(+), 12 deletions(-)

M handlers.go
M handlers.go => handlers.go +14 -12
@@ 209,25 209,27 @@ func proxy(w http.ResponseWriter, r *http.Request) {
		http.Redirect(w, r, "/?url="+gmi.QueryEscape(targetURL), http.StatusFound)
	}

	var u *url.URL
	var err error = nil
	if r.URL.Query().Get("url") == "" {
		if homepage != nil {
			gemini.ProxyGemini(w, r, homepage)
		} else {
		if homepage == nil {
			err := templates.Templates.ExecuteTemplate(w, "home.html.tmpl", templates.TemplateData{})
			if err != nil {
				log.Println("proxy:", err)
				http.Error(w, "Internal Server Error", 500)
			}
			return
		} else {
			u = homepage
		}
	} else {
		u, err = url.Parse(r.URL.Query().Get("url"))
		if err != nil {
			err = fmt.Errorf("proxy: failed to parse URL: %v", err)
			log.Println(err)
			http.Error(w, err.Error(), 500)
			return
		}
		return
	}

	u, err := url.Parse(r.URL.Query().Get("url"))
	if err != nil {
		err = fmt.Errorf("proxy: failed to parse URL: %v", err)
		log.Println(err)
		http.Error(w, err.Error(), 500)
		return
	}

	switch u.Scheme {