Files
ersteller/starter/routes/routing.go
T
2025-09-17 17:32:50 +02:00

86 lines
2.4 KiB
Go

package routes
import (
. "ersteller-lib"
"ersteller-lib/authentication"
"ersteller-lib/starter/about"
"ersteller-lib/starter/contact"
"ersteller-lib/starter/ent"
"ersteller-lib/starter/env"
"ersteller-lib/starter/google"
"ersteller-lib/starter/index"
"ersteller-lib/starter/page"
"net/http"
"github.com/gorilla/sessions"
. "maragu.dev/gomponents"
)
func CreateApi(environment env.Environment, db *ent.Client) http.Handler {
server := NewHtmxServer()
HtmxRouteDebugTrace = true
sessionStore := sessions.NewCookieStore([]byte(environment.SessionSecret))
//sessionStore.Options.Secure = false
if !environment.IsDev {
sessionStore.Options.Secure = true
sessionStore.Options.HttpOnly = true
}
googleAuth := google.NewGoogleAuth(db, server.GetHttpServer(), environment, sessionStore)
googleAuth.AddRoutes()
indexActivePath := NewActivePath(map[Language]string{
En: "Home",
De: "Startseite",
}, LanguagePaths{
En: index.IndexPath,
De: index.IndexPathDe,
})
aboutActivePath := NewActivePath(map[Language]string{
En: "About",
De: "Über uns",
}, LanguagePaths{
En: about.AboutPath,
De: about.AboutPathDe,
})
contactActivePath := NewActivePath(map[Language]string{
En: "Contact",
De: "Kontakt",
}, LanguagePaths{
En: contact.ContactPath,
De: contact.ContactPathDe,
})
// Main navigation items
activePaths := []ActivePath{indexActivePath, aboutActivePath, contactActivePath}
// Footer navigation items (placeholder - can be customized)
footerPaths := []ActivePath{}
createPageFunc := createPage(activePaths, footerPaths)
indexPage := index.NewPage(createPageFunc, server, &indexActivePath)
server.HandleStaticAndDefaultPath(indexPage.ViewRoute, En)
// Create About and Contact pages using the new packages
_ = about.NewPage(createPageFunc, server, &aboutActivePath)
_ = contact.NewPage(createPageFunc, server, &contactActivePath)
serverWithMiddleWare := UseMiddleware(server, LoggingMiddleware, MakeGzipHandler,
authentication.Middleware(sessionStore,
[]string{"/login", google.GoogleLogin, google.GoogleLoginCallback}, "/"))
return serverWithMiddleWare
}
func createPage(activePaths []ActivePath, footerPaths []ActivePath) CreateHtmxPageFunc {
return func(req HtmxContext, metadata PageWebsiteMetaData, content ...Node) {
metadata.NavItems = activePaths
metadata.FooterNavItems = footerPaths
page.CreatePage(req, metadata, content...)
}
}