flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit 58a76b756308ca8920f3091d35caf8220605f3da
parent 2c4af350e9bf03df30a01a807c697bb652033911
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sat,  9 Jan 2021 17:46:51 -0800

custom domain fixes

Diffstat:
Mgemini.go | 10++++++++--
Mhttp.go | 3++-
2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/gemini.go b/gemini.go @@ -79,8 +79,14 @@ func gmiIndex(w *gmi.ResponseWriter, r *gmi.Request) { } func gmiPage(w *gmi.ResponseWriter, r *gmi.Request) { - logGemini(r) // TODO move into wrapper - userName := filepath.Clean(strings.Split(r.URL.Host, ".")[0]) // clean probably unnecessary + logGemini(r) // TODO move into wrapper + var userName string + custom := domains[r.Host] + if custom != "" { + userName = custom + } else { + userName := filepath.Clean(strings.Split(r.URL.Host, ".")[0]) // clean probably unnecessary + } fileName := filepath.Clean(r.URL.Path) if fileName == "/" { fileName = "index.gmi" diff --git a/http.go b/http.go @@ -301,7 +301,8 @@ func myAccountHandler(w http.ResponseWriter, r *http.Request) { newDomain := r.Form.Get("domain") newUsername = strings.ToLower(newUsername) var err error - if newDomain != me.Domain { + _, exists := dict[newDomain] + if newDomain != me.Domain && !exists { _, err = DB.Exec("update user set domain = ? where username = ?", newDomain, me.Username) // TODO use transaction if err != nil { errors = append(errors, err.Error())