98 lines
2.7 KiB
Go
98 lines
2.7 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/login"
|
|
"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)
|
|
|
|
// Create Login page
|
|
loginPaths := LanguagePaths{
|
|
En: login.LoginPath,
|
|
De: login.LoginPathDe,
|
|
}
|
|
loginActivePath := NewActivePath(map[Language]string{
|
|
En: "Login",
|
|
De: "Anmelden",
|
|
}, loginPaths)
|
|
_ = login.NewPage(createPageFunc, server, &loginActivePath)
|
|
|
|
serverWithMiddleWare := UseMiddleware(server, LoggingMiddleware, MakeGzipHandler,
|
|
authentication.Middleware(sessionStore,
|
|
[]string{"/de" + login.LoginPathDe, "/en" + authentication.LoginPath, google.GoogleLogin, google.GoogleLoginCallback, "/static"}, loginPaths))
|
|
|
|
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...)
|
|
}
|
|
}
|