~evanj/cms

ref: 715dccc30b27b8e6bdd6330ff3d106e66f577087 cms/internal/c/static/static.go -rw-r--r-- 781 bytes
715dccc3Evan M Jones Fix(new*List): Remove error, remove panic when list is of size zero. 1 year, 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package static

import (
	"log"
	"net/http"

	"git.sr.ht/~evanj/cms/internal/c"
	"git.sr.ht/~evanj/cms/internal/m/user"
	"git.sr.ht/~evanj/cms/internal/s/tmpl"
)

type Ping struct {
	*c.Controller
	log *log.Logger
}

var tinymce = tmpl.MustParse("css/tinymce.css")

type dber interface {
	UserGet(username, password string) (user.User, error)
	UserGetFromToken(token string) (user.User, error)
}

func New(log *log.Logger, db dber) *Ping {
	return &Ping{
		c.New(log, db),
		log,
	}
}

func (p *Ping) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	switch r.URL.Path {
	case "/static/tinymce.css":
		w.Header().Add("Content-Type", "text/css")
		w.WriteHeader(http.StatusOK)
		_ = tinymce.Execute(w, nil) // TODO: Will this ever fail? When?
		return
	}

	http.NotFound(w, r)
}