Add editor

This includes the '/' route handler
This commit is contained in:
Matt Baer
2018-11-08 00:11:42 -05:00
parent a30fc5b52b
commit 86e7ba2579
21 changed files with 787 additions and 0 deletions

21
app.go
View File

@@ -8,6 +8,7 @@ import (
"net/http"
"os"
"os/signal"
"regexp"
"syscall"
"github.com/gorilla/mux"
@@ -37,6 +38,25 @@ type app struct {
sessionStore *sessions.CookieStore
}
// handleViewHome shows page at root path. Will be the Pad if logged in and the
// catch-all landing page otherwise.
func handleViewHome(app *app, w http.ResponseWriter, r *http.Request) error {
if app.cfg.App.SingleUser {
// Render blog index
return handleViewCollection(app, w, r)
}
// Multi-user instance
u := getUserSession(app, r)
if u != nil {
// User is logged in, so show the Pad
return handleViewPad(app, w, r)
}
// Show landing page
return renderPage(w, "landing.tmpl", pageForReq(app, r))
}
func pageForReq(app *app, r *http.Request) page.StaticPage {
p := page.StaticPage{
AppCfg: app.cfg.App,
@@ -67,6 +87,7 @@ func pageForReq(app *app, r *http.Request) page.StaticPage {
}
var shttp = http.NewServeMux()
var fileRegex = regexp.MustCompile("/([^/]*\\.[^/]*)$")
func Serve() {
debugPtr := flag.Bool("debug", false, "Enables debug logging.")