2024-01-22 23:10:14 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/go-chi/chi/v5"
|
2024-01-24 14:46:04 -05:00
|
|
|
|
|
|
|
"git.burning.moe/celediel/burning.moe/internal/config"
|
|
|
|
"git.burning.moe/celediel/burning.moe/internal/handlers"
|
2024-01-22 23:10:14 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// routes handles all of the HTTP setup. Middleware is enabled,
|
|
|
|
// static fileserver is setup, and handlers are ... handled
|
|
|
|
func routes(app *config.AppConfig) http.Handler {
|
|
|
|
mux := chi.NewRouter()
|
|
|
|
|
|
|
|
// Import some middleware
|
2024-01-25 02:33:08 -05:00
|
|
|
for _, mw := range Middleware {
|
|
|
|
mux.Use(mw)
|
|
|
|
}
|
2024-01-22 23:10:14 -05:00
|
|
|
|
|
|
|
// Setup static file server
|
|
|
|
app.Logger.Debug("Setting up /static file server")
|
|
|
|
mux.Handle("/static/*", http.StripPrefix("/static", http.FileServer(http.Dir("./static"))))
|
|
|
|
|
|
|
|
// Setup routes for handlers
|
|
|
|
for _, handler := range handlers.Handlers {
|
|
|
|
app.Logger.Info("Setting up handler for " + handler.Handles)
|
|
|
|
mux.Get(handler.Handles, handler.Handler)
|
|
|
|
}
|
|
|
|
|
2024-01-27 19:28:03 -05:00
|
|
|
// Setup extra handlers
|
2024-01-24 03:20:07 -05:00
|
|
|
mux.Get("/", handlers.HomeHandler)
|
2024-01-27 19:28:03 -05:00
|
|
|
mux.Get("/robots.txt", handlers.RobotHandler)
|
2024-01-24 03:20:07 -05:00
|
|
|
|
2024-01-22 23:10:14 -05:00
|
|
|
return mux
|
|
|
|
}
|