|
|
|
|
@ -356,28 +356,35 @@ func main() {
|
|
|
|
|
log.Fatal("Error getting working directory:", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Parse partial templates
|
|
|
|
|
// Parse base and partial templates
|
|
|
|
|
tmpl := template.Must(template.ParseFiles(
|
|
|
|
|
filepath.Join(dir, "templates/base.html"),
|
|
|
|
|
filepath.Join(dir, "templates/partials/navbar.html"),
|
|
|
|
|
filepath.Join(dir, "templates/partials/cookie_banner.html"),
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
// Parse page-specific templates with unique names
|
|
|
|
|
tmpl, err = tmpl.ParseFiles(
|
|
|
|
|
filepath.Join(dir, "templates/pages/about.html"),
|
|
|
|
|
filepath.Join(dir, "templates/pages/board.html"),
|
|
|
|
|
filepath.Join(dir, "templates/pages/boards.html"),
|
|
|
|
|
filepath.Join(dir, "templates/pages/home.html"),
|
|
|
|
|
filepath.Join(dir, "templates/pages/login.html"),
|
|
|
|
|
filepath.Join(dir, "templates/pages/news.html"),
|
|
|
|
|
filepath.Join(dir, "templates/pages/profile.html"),
|
|
|
|
|
filepath.Join(dir, "templates/pages/profile_edit.html"),
|
|
|
|
|
filepath.Join(dir, "templates/pages/signup.html"),
|
|
|
|
|
filepath.Join(dir, "templates/pages/thread.html"),
|
|
|
|
|
filepath.Join(dir, "templates/pages/userhome.html"),
|
|
|
|
|
filepath.Join(dir, "templates/pages/chat.html"),
|
|
|
|
|
filepath.Join(dir, "templates/pages/preferences.html"),
|
|
|
|
|
)
|
|
|
|
|
pageTemplates := []string{
|
|
|
|
|
"about.html",
|
|
|
|
|
"board.html",
|
|
|
|
|
"boards.html",
|
|
|
|
|
"home.html",
|
|
|
|
|
"login.html",
|
|
|
|
|
"news.html",
|
|
|
|
|
"profile.html",
|
|
|
|
|
"profile_edit.html",
|
|
|
|
|
"signup.html",
|
|
|
|
|
"thread.html",
|
|
|
|
|
"userhome.html",
|
|
|
|
|
"chat.html",
|
|
|
|
|
"preferences.html",
|
|
|
|
|
}
|
|
|
|
|
pagePaths := make([]string, 0, len(pageTemplates))
|
|
|
|
|
for _, name := range pageTemplates {
|
|
|
|
|
pagePaths = append(pagePaths, filepath.Join(dir, "templates/pages", name))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tmpl, err = tmpl.ParseFiles(pagePaths...)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal("Error parsing page templates:", err)
|
|
|
|
|
}
|
|
|
|
|
@ -404,23 +411,30 @@ func main() {
|
|
|
|
|
fs := http.FileServer(http.Dir("static"))
|
|
|
|
|
http.Handle(config.ThreadrDir+"/static/", http.StripPrefix(config.ThreadrDir+"/static/", fs))
|
|
|
|
|
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+"/", app.SessionMW(handlers.HomeHandler(app)))
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+"/login/", app.SessionMW(handlers.LoginHandler(app)))
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+"/logout/", app.SessionMW(handlers.LogoutHandler(app)))
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+"/userhome/", app.SessionMW(app.RequireLoginMW(handlers.UserHomeHandler(app))))
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+"/boards/", app.SessionMW(handlers.BoardsHandler(app)))
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+"/board/", app.SessionMW(handlers.BoardHandler(app)))
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+"/thread/", app.SessionMW(handlers.ThreadHandler(app)))
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+"/about/", app.SessionMW(handlers.AboutHandler(app)))
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+"/profile/", app.SessionMW(app.RequireLoginMW(handlers.ProfileHandler(app))))
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+"/profile/edit/", app.SessionMW(app.RequireLoginMW(handlers.ProfileEditHandler(app))))
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+"/preferences/", app.SessionMW(app.RequireLoginMW(handlers.PreferencesHandler(app))))
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+"/like/", app.SessionMW(app.RequireLoginMW(handlers.LikeHandler(app))))
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+"/news/", app.SessionMW(handlers.NewsHandler(app)))
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+"/signup/", app.SessionMW(handlers.SignupHandler(app)))
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+"/accept_cookie/", app.SessionMW(handlers.AcceptCookieHandler(app)))
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+"/chat/", app.SessionMW(app.RequireLoginMW(handlers.ChatHandler(app))))
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+"/file", app.SessionMW(handlers.FileHandler(app)))
|
|
|
|
|
handle := func(path string, handler http.HandlerFunc) {
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+path, app.SessionMW(handler))
|
|
|
|
|
}
|
|
|
|
|
handleAuthed := func(path string, handler http.HandlerFunc) {
|
|
|
|
|
http.HandleFunc(config.ThreadrDir+path, app.SessionMW(app.RequireLoginMW(handler)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handle("/", handlers.HomeHandler(app))
|
|
|
|
|
handle("/login/", handlers.LoginHandler(app))
|
|
|
|
|
handle("/logout/", handlers.LogoutHandler(app))
|
|
|
|
|
handleAuthed("/userhome/", handlers.UserHomeHandler(app))
|
|
|
|
|
handle("/boards/", handlers.BoardsHandler(app))
|
|
|
|
|
handle("/board/", handlers.BoardHandler(app))
|
|
|
|
|
handle("/thread/", handlers.ThreadHandler(app))
|
|
|
|
|
handle("/about/", handlers.AboutHandler(app))
|
|
|
|
|
handleAuthed("/profile/", handlers.ProfileHandler(app))
|
|
|
|
|
handleAuthed("/profile/edit/", handlers.ProfileEditHandler(app))
|
|
|
|
|
handleAuthed("/preferences/", handlers.PreferencesHandler(app))
|
|
|
|
|
handleAuthed("/like/", handlers.LikeHandler(app))
|
|
|
|
|
handle("/news/", handlers.NewsHandler(app))
|
|
|
|
|
handle("/signup/", handlers.SignupHandler(app))
|
|
|
|
|
handle("/accept_cookie/", handlers.AcceptCookieHandler(app))
|
|
|
|
|
handleAuthed("/chat/", handlers.ChatHandler(app))
|
|
|
|
|
handle("/file", handlers.FileHandler(app))
|
|
|
|
|
|
|
|
|
|
log.Println("Server starting on :8080")
|
|
|
|
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
|
|
|
|