package main
import (
"embed"
"html/template"
"net/http"
"git.chandlerswift.com/chandlerswift/svs-services-server/page"
)
//go:embed templates/index.html
var indexTemplate string
//go:embed templates/404.html
var notFoundTemplate string
//go:embed headshots/*
var headshots embed.FS
var tmpl = template.Must(template.New("index").Parse(indexTemplate))
var notFoundTmpl = template.Must(template.New("404").Parse(notFoundTemplate))
func main() {
http.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) {
host := r.Host
pageData := page.GenerateDummyData(host)
tmpl.Execute(w, pageData)
})
// Serve embedded headshots file
http.Handle("/headshots/", http.FileServer(http.FS(headshots)))
// 404 handler
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
notFoundTmpl.Execute(w, nil)
})
http.ListenAndServe(":8080", nil) // TODO: configurable port
}