From 775621e5e9998a65dcbc319af5e9a2b22bee6dbd Mon Sep 17 00:00:00 2001 From: Max Amundsen Date: Sun, 9 Mar 2025 17:10:48 -0400 Subject: [PATCH] oops --- .gitignore | 4 ---- cmd/server/main.go | 40 ++++++++++++++++++++++++++++++++++++++++ cmd/server/routes.go | 28 ++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 cmd/server/main.go create mode 100644 cmd/server/routes.go diff --git a/.gitignore b/.gitignore index cafbf9f..2324cc3 100644 --- a/.gitignore +++ b/.gitignore @@ -43,14 +43,10 @@ metagen_config.json *.metagen.go *.metagen.css -.metagen # jet autogenerated models/table structs .jet/ -server -!./cmd/server - #env / secrets .env diff --git a/cmd/server/main.go b/cmd/server/main.go new file mode 100644 index 0000000..3ce3fe9 --- /dev/null +++ b/cmd/server/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "fmt" + "log" + "net/http" + "maxwarden/config" + "maxwarden/database" + "maxwarden/handlers" + "maxwarden/security" + "maxwarden/tasks" +) + +func main() { + fmt.Println("Previous: A powerful web codebase.") + + if config.DEBUG { + fmt.Println("DEBUG BUILD") + } else { + fmt.Println("RELEASE BUILD") + } + + config.Init() + security.Init() + database.Init() + handlers.Init() + tasks.Init() + + mux := http.NewServeMux() + mapRoutes(mux) + + log.Println("Mapped HTTP routes") + log.Println("Listening on http://" + config.GetConfig().Host + ":" + config.GetConfig().Port) + + serveErr := http.ListenAndServe(config.GetConfig().Host+":"+config.GetConfig().Port, mux) + + if serveErr != nil { + log.Fatal(serveErr) + } +} diff --git a/cmd/server/routes.go b/cmd/server/routes.go new file mode 100644 index 0000000..fb12bda --- /dev/null +++ b/cmd/server/routes.go @@ -0,0 +1,28 @@ +package main + +import ( + // "maxwarden/middleware" + "net/http" + "maxwarden/handlers" + "maxwarden/handlers/app" + "maxwarden/handlers/auth" + "maxwarden/middleware" +) + +func mapRoutes(mux *http.ServeMux) { + id := middleware.LoadIdentity + sess := middleware.LoadSession + // cors := middleware.EnableCors + + mux.HandleFunc("/app/account", id(sess(app.AccountHandler), true)) + mux.HandleFunc("/app", id(sess(app.VaultHandler), true)) + mux.HandleFunc("/app/generator", id(sess(app.GeneratorHandler), true)) + mux.HandleFunc("/app/generator-hx", id(sess(app.GeneratorHxHandler), true)) + mux.HandleFunc("/app/vault-hx", id(sess(app.VaultHxHandler), true)) + mux.HandleFunc("/app/delete/{id}", id(sess(app.DeleteHandler), true)) + mux.HandleFunc("/app/editor/add", id(sess(app.EditorHandler), true)) + mux.HandleFunc("/app/editor/edit/{id}", id(sess(app.EditorHandler), true)) + mux.HandleFunc("/auth/login", id(sess(auth.LoginHandler), true)) + mux.HandleFunc("/auth/logout", id(sess(auth.LogoutHandler), true)) + mux.HandleFunc("/", handlers.IndexHandler) +}