all repos — flounder @ 7dff255849f753cf7b0d73de584f3bb6cb6f1645

A small site builder for the Gemini protocol

Add wildcard domains to gemini
alex wennerberg alex@alexwennerberg.com
Wed, 21 Oct 2020 22:16:18 -0700
commit

7dff255849f753cf7b0d73de584f3bb6cb6f1645

parent

8e3a3b5bff7f3f9fd98b1cf8c3d636623b7164ff

7 files changed, 28 insertions(+), 16 deletions(-)

jump to
M config.goconfig.go

@@ -5,11 +5,11 @@ "github.com/BurntSushi/toml"

) type Config struct { - FilesPath string - RootDomain string - SiteTitle string - Debug bool - SecretKey string + FilesDirectory string + RootDomain string + SiteTitle string + Debug bool + SecretKey string } func getConfig(filename string) (Config, error) {
D config.toml

@@ -1,4 +0,0 @@

-site_title="flounder" -root_domain="localhost:8080" -debug=true -
M flounder.tomlflounder.toml

@@ -1,3 +1,4 @@

SiteTitle="🐟flounder" -RootDomain="localhost:8080" +RootDomain="localhost" +FilesDirectory="./files"
M gemini.gogemini.go

@@ -5,11 +5,13 @@ "bytes"

"crypto/tls" "crypto/x509" // todo move into cert file "encoding/pem" + "strings" // "fmt" "git.sr.ht/~adnano/gmi" + "io/ioutil" "log" "os" - // "path" + "path" "text/template" "time" )

@@ -34,9 +36,19 @@ t.Execute(w, data)

} func gmiPage(w *gmi.ResponseWriter, r *gmi.Request) { + userName := strings.Split(r.URL.Host, ".")[0] + fileName := path.Join(c.FilesDirectory, userName, r.URL.Path) + data, err := ioutil.ReadFile(fileName) + if err != nil { + // return 404 equivalent + log.Fatal(err) + } + // TODO handle error + w.Write(data) } -func runGeminiServer(config *Config) { +func runGeminiServer() { + log.Println("Starting gemini server") var server gmi.Server if err := server.CertificateStore.Load("./tmpcerts"); err != nil {

@@ -70,7 +82,8 @@ return cert

} // replace with wildcard cert - server.HandleFunc("localhost", gmiIndex) + server.HandleFunc(c.RootDomain, gmiIndex) + server.HandleFunc("*."+c.RootDomain, gmiPage) server.ListenAndServe() }
M go.modgo.mod

@@ -3,7 +3,7 @@

go 1.15 require ( - git.sr.ht/~adnano/gmi v0.1.0-alpha.1 + git.sr.ht/~adnano/gmi v0.1.0-alpha.2 github.com/BurntSushi/toml v0.3.1 github.com/mattn/go-sqlite3 v1.14.4 )
M go.sumgo.sum

@@ -1,5 +1,7 @@

git.sr.ht/~adnano/gmi v0.1.0-alpha.1 h1:5sha5ucev32U95drEEaPw9rm6hGWJtL8y5HViQ3VDJQ= git.sr.ht/~adnano/gmi v0.1.0-alpha.1/go.mod h1:t/m2KtH+7lXIF7jjVN+bNvwPbE0nxHOpvlA/WZ/KeLQ= +git.sr.ht/~adnano/gmi v0.1.0-alpha.2 h1:5/wzImYT3mJmZ27lazJ8YAdpiVN3QNJruLX7PXOITeo= +git.sr.ht/~adnano/gmi v0.1.0-alpha.2/go.mod h1:t/m2KtH+7lXIF7jjVN+bNvwPbE0nxHOpvlA/WZ/KeLQ= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
M main.gomain.go

@@ -71,7 +71,7 @@ c, err = getConfig(*configPath)

if err != nil { log.Fatal(err) } - runHTTPServer() - // runGeminiServer(&config) + // runHTTPServer() + runGeminiServer() // go log.Fatal(gmi.ListenAndServe(":8080", nil)) }