aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/server/serve.go
blob: 9e7b722aac82eb997e9ab5def6f7e5b3c7640736 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package server

import (
	"net/http"

	"github.com/LMBishop/scrapbook/pkg/html"
	"github.com/LMBishop/scrapbook/pkg/index"
)

func ServeSite(siteIndex *index.SiteIndex) func(w http.ResponseWriter, r *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		site := siteIndex.GetSiteByHost(r.Host)
		if site == nil {
			w.WriteHeader(http.StatusNotFound)
			html.NotFoundSitePage(r.Host)
			return
		}

		site.Handler.ServeHTTP(w, r)
	}
}