Initial Setup
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"git.alexdickens.com/Alex/BedrockCMS/web"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/go-chi/cors"
|
||||
)
|
||||
|
||||
var tmpl = template.Must(template.ParseFS(web.Templates, "template/*.html"))
|
||||
|
||||
func main() {
|
||||
r := chi.NewRouter()
|
||||
r.Use(middleware.Logger)
|
||||
r.Use(middleware.Recoverer)
|
||||
|
||||
r.Use(cors.Handler(cors.Options{
|
||||
AllowedOrigins: []string{"*"},
|
||||
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
|
||||
AllowedHeaders: []string{"Authorization", "Content-Type"},
|
||||
}))
|
||||
|
||||
r.Get("/healthz", func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Write([]byte("ok"))
|
||||
})
|
||||
|
||||
r.Get("/", func(w http.ResponseWriter, req *http.Request) {
|
||||
data := map[string]any{"Title": "Bedrock CMS", "Message": "This Is A Message"}
|
||||
if err := tmpl.ExecuteTemplate(w, "base", data); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
})
|
||||
|
||||
http.ListenAndServe(":8080", r)
|
||||
}
|
||||
Reference in New Issue
Block a user