Compare commits
No commits in common. "177556399dde3ceee90a33abf82c3ad3ca475997" and "df3adcde91ec9889242b3be8cfb6b557d8cab3da" have entirely different histories.
177556399d
...
df3adcde91
|
@ -11,12 +11,9 @@ import (
|
||||||
"git.burning.moe/celediel/burning.moe/internal/render"
|
"git.burning.moe/celediel/burning.moe/internal/render"
|
||||||
)
|
)
|
||||||
|
|
||||||
// App wide config data and such
|
|
||||||
var app config.AppConfig
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Initialise app and config
|
// Initialise app and config
|
||||||
app = config.Initialise()
|
app := config.Initialise()
|
||||||
|
|
||||||
// Initialise handlers and renderer
|
// Initialise handlers and renderer
|
||||||
handlers.Initialise(&app)
|
handlers.Initialise(&app)
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5/middleware"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Middleware is a slice of Middleware (aka func(n http.Handler) http.Handler {})
|
|
||||||
var Middleware []func(next http.Handler) http.Handler = []func(next http.Handler) http.Handler{
|
|
||||||
// chi's recommended list
|
|
||||||
middleware.RequestID,
|
|
||||||
middleware.RealIP,
|
|
||||||
// plus custom request logger
|
|
||||||
func(next http.Handler) http.Handler {
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
app.Logger.Info("REQUEST", "url", r.URL, "ip", r.RemoteAddr, "useragent", r.UserAgent())
|
|
||||||
next.ServeHTTP(w, r)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
middleware.Recoverer,
|
|
||||||
}
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
|
"github.com/go-chi/chi/v5/middleware"
|
||||||
|
|
||||||
"git.burning.moe/celediel/burning.moe/internal/config"
|
"git.burning.moe/celediel/burning.moe/internal/config"
|
||||||
"git.burning.moe/celediel/burning.moe/internal/handlers"
|
"git.burning.moe/celediel/burning.moe/internal/handlers"
|
||||||
|
@ -15,9 +16,7 @@ func routes(app *config.AppConfig) http.Handler {
|
||||||
mux := chi.NewRouter()
|
mux := chi.NewRouter()
|
||||||
|
|
||||||
// Import some middleware
|
// Import some middleware
|
||||||
for _, mw := range Middleware {
|
mux.Use(middleware.Recoverer)
|
||||||
mux.Use(mw)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup static file server
|
// Setup static file server
|
||||||
app.Logger.Debug("Setting up /static file server")
|
app.Logger.Debug("Setting up /static file server")
|
||||||
|
|
|
@ -36,8 +36,6 @@ type ConfigDatabase struct {
|
||||||
// Initialises the app wide AppConfig, loads values from environment, and set up the Logger
|
// Initialises the app wide AppConfig, loads values from environment, and set up the Logger
|
||||||
func Initialise() AppConfig {
|
func Initialise() AppConfig {
|
||||||
app := *defaults
|
app := *defaults
|
||||||
|
|
||||||
// Setup logger
|
|
||||||
app.Logger = log.NewWithOptions(os.Stderr, log.Options{
|
app.Logger = log.NewWithOptions(os.Stderr, log.Options{
|
||||||
ReportTimestamp: true,
|
ReportTimestamp: true,
|
||||||
TimeFormat: time.TimeOnly,
|
TimeFormat: time.TimeOnly,
|
||||||
|
|
|
@ -44,6 +44,8 @@ func Initialise(a *config.AppConfig) {
|
||||||
|
|
||||||
// HomeHandler handles /, generating data from Handlers
|
// HomeHandler handles /, generating data from Handlers
|
||||||
func HomeHandler(w http.ResponseWriter, r *http.Request) {
|
func HomeHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
app.Logger.Info("Got request for homepage")
|
||||||
|
|
||||||
page := "home.page.tmpl"
|
page := "home.page.tmpl"
|
||||||
d := models.TemplateData{}
|
d := models.TemplateData{}
|
||||||
|
|
||||||
|
@ -78,6 +80,7 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// makeBasicHandler returns a simple handler that renders a template from `name`.page.tmpl
|
// makeBasicHandler returns a simple handler that renders a template from `name`.page.tmpl
|
||||||
func makeBasicHandler(name string) func(w http.ResponseWriter, r *http.Request) {
|
func makeBasicHandler(name string) func(w http.ResponseWriter, r *http.Request) {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
app.Logger.Infof("Got request for %s page", name)
|
||||||
pageName := name + ".page.tmpl"
|
pageName := name + ".page.tmpl"
|
||||||
render.RenderTemplate(w, pageName)
|
render.RenderTemplate(w, pageName)
|
||||||
}
|
}
|
||||||
|
@ -92,6 +95,7 @@ func makeLinksHandler(name string) func(w http.ResponseWriter, r *http.Request)
|
||||||
app.Logger.Error(fmt.Sprintf("couldn't get %s from cache", page), "err", err)
|
app.Logger.Error(fmt.Sprintf("couldn't get %s from cache", page), "err", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.Logger.Infof("Got request for %s links page", name)
|
||||||
data, err := td.LoadTemplateData(name)
|
data, err := td.LoadTemplateData(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.Logger.Fatal("couldn't load template data for "+name, "err", err)
|
app.Logger.Fatal("couldn't load template data for "+name, "err", err)
|
||||||
|
|
Loading…
Reference in a new issue