Start outputting HTML
All checks were successful
Build and copy to prod / build-and-copy (push) Successful in 36s

This commit is contained in:
Lewis Dale 2024-05-14 12:52:36 +01:00
parent a7a55b6a90
commit 27f6d749d3
2 changed files with 19 additions and 3 deletions

13
main.go
View File

@ -1,7 +1,9 @@
package main
import (
"embed"
"encoding/json"
"html/template"
"net/http"
_ "github.com/mattn/go-sqlite3"
@ -10,6 +12,9 @@ import (
"lewisdale.dev/oopsie/sites"
)
//go:embed templates/*
var content embed.FS
func main() {
db := data.Connect("test.sqlite3")
@ -31,13 +36,15 @@ func main() {
http.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
pings := ping.ListGroupedBySite(db)
if output, err := json.Marshal(pings); err != nil {
if _, err := json.Marshal(pings); err != nil {
w.Write([]byte(err.Error()))
w.WriteHeader(http.StatusInternalServerError)
return
} else {
w.Header().Set("Content-Type", "application/json")
w.Write(output)
w.Header().Set("Content-Type", "text/html")
t, _ := template.ParseFS(content, "templates/index.html")
t.Execute(w, nil)
}
})

9
templates/index.html Normal file
View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Oopsie</title>
</head>
<body>
<h1>Oopsie uptime monitoring</h1>
</body>
</html>