Skip to content
Snippets Groups Projects
Verified Commit c4dbd847 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Initial working implementation

parent 62861d72
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"net/http" "net/http"
"os" "os"
"path" "path"
"strings"
) )
type Config struct { type Config struct {
...@@ -57,8 +58,10 @@ func main() { ...@@ -57,8 +58,10 @@ func main() {
panic(err) panic(err)
} }
assets := http.FileServer(http.Dir("assets"))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_, channel := path.Split(r.URL.Path) _, channel := path.Split(r.URL.Path)
if strings.HasPrefix(channel, "#") {
channelData := ChannelData{} channelData := ChannelData{}
err = db.QueryRow("SELECT id, channel FROM channels WHERE channel ILIKE $1", channel).Scan(&channelData.Id, &channelData.Name) err = db.QueryRow("SELECT id, channel FROM channels WHERE channel ILIKE $1", channel).Scan(&channelData.Id, &channelData.Name)
if err != nil { if err != nil {
...@@ -75,6 +78,11 @@ func main() { ...@@ -75,6 +78,11 @@ func main() {
println(err.Error()) println(err.Error())
return return
} }
} else {
w.Header().Set("Vary", "Accept-Encoding")
w.Header().Set("Cache-Control", "public, max-age=31536000")
assets.ServeHTTP(w, r)
}
}) })
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment