rearranged middleware so it's not all tied to the base Echo instance (will be important later)

This commit is contained in:
2026-02-22 22:18:16 -07:00
parent 43c34c9ffc
commit 7b40c04897
+41 -36
View File
@@ -46,43 +46,45 @@ func setupEcho() *echo.Echo {
} else { } else {
log.Warn("WARNING: --debug-panic in effect - DO NOT use this in production!") log.Warn("WARNING: --debug-panic in effect - DO NOT use this in production!")
} }
e.Use(LogrusMiddleware, ui.SessionStoreInjector, ui.ContextCreator) e.Use(LogrusMiddleware)
e.Use(ui.IPBanTest, ui.CookieLoginTest)
e.Match(GetAndPost, "/TODO/*", ui.AmWrap(NotImplPage)) // This is the set of all middleware functions used by the UI, as opposed to other things.
uiset := []echo.MiddlewareFunc{ui.SessionStoreInjector, ui.ContextCreator, ui.IPBanTest, ui.CookieLoginTest}
e.Match(GetAndPost, "/TODO/*", ui.AmWrap(NotImplPage), uiset...)
e.GET("/img/*", ui.AmServeImage) e.GET("/img/*", ui.AmServeImage)
e.GET("/static/*", ui.AmStaticFileHandler()) e.GET("/static/*", ui.AmStaticFileHandler())
e.GET("/go/:postlink", ui.AmWrap(JumpToShortcut)) e.GET("/go/:postlink", ui.AmWrap(JumpToShortcut))
e.GET("/", ui.AmWrap(TopPage)) e.GET("/", ui.AmWrap(TopPage), uiset...)
e.GET("/about", ui.AmWrap(AboutPage)) e.GET("/about", ui.AmWrap(AboutPage), uiset...)
e.GET("/login", ui.AmWrap(LoginForm)) e.GET("/login", ui.AmWrap(LoginForm), uiset...)
e.POST("/login", ui.AmWrap(Login)) e.POST("/login", ui.AmWrap(Login), uiset...)
e.GET("/logout", ui.AmWrap(Logout)) e.GET("/logout", ui.AmWrap(Logout), uiset...)
e.GET("/newacct", ui.AmWrap(NewAccountUserAgreement)) e.GET("/newacct", ui.AmWrap(NewAccountUserAgreement), uiset...)
e.GET("/newacct2", ui.AmWrap(NewAccountForm)) e.GET("/newacct2", ui.AmWrap(NewAccountForm), uiset...)
e.POST("/newacct2", ui.AmWrap(NewAccount)) e.POST("/newacct2", ui.AmWrap(NewAccount), uiset...)
e.GET("/verify", ui.AmWrap(VerifyEmailForm)) e.GET("/verify", ui.AmWrap(VerifyEmailForm), uiset...)
e.POST("/verify", ui.AmWrap(VerifyEMail)) e.POST("/verify", ui.AmWrap(VerifyEMail), uiset...)
e.GET("/passrecovery/:uid/:auth", ui.AmWrap(PasswordRecovery)) e.GET("/passrecovery/:uid/:auth", ui.AmWrap(PasswordRecovery), uiset...)
e.GET("/profile", ui.AmWrap(EditProfileForm)) e.GET("/profile", ui.AmWrap(EditProfileForm), uiset...)
e.POST("/profile", ui.AmWrap(EditProfile)) e.POST("/profile", ui.AmWrap(EditProfile), uiset...)
e.GET("/profile_photo", ui.AmWrap(ProfilePhotoForm)) e.GET("/profile_photo", ui.AmWrap(ProfilePhotoForm), uiset...)
e.POST("/profile_photo", ui.AmWrap(ProfilePhoto)) e.POST("/profile_photo", ui.AmWrap(ProfilePhoto), uiset...)
e.GET("/find", ui.AmWrap(FindPage)) e.GET("/find", ui.AmWrap(FindPage), uiset...)
e.POST("/find", ui.AmWrap(Find)) e.POST("/find", ui.AmWrap(Find), uiset...)
e.GET("/user/:uname", ui.AmWrap(ShowProfile)) e.GET("/user/:uname", ui.AmWrap(ShowProfile), uiset...)
e.POST("/quick_email", ui.AmWrap(QuickEMail)) e.POST("/quick_email", ui.AmWrap(QuickEMail), uiset...)
e.GET("/hotlist", ui.AmWrap(Hotlist)) e.GET("/hotlist", ui.AmWrap(Hotlist), uiset...)
e.GET("/sideboxes", ui.AmWrap(ManageSideboxes)) e.GET("/sideboxes", ui.AmWrap(ManageSideboxes), uiset...)
e.POST("/sideboxes", ui.AmWrap(AddSidebox)) e.POST("/sideboxes", ui.AmWrap(AddSidebox), uiset...)
e.GET("/create_comm", ui.AmWrap(CreateCommunityForm)) e.GET("/create_comm", ui.AmWrap(CreateCommunityForm), uiset...)
e.POST("/create_comm", ui.AmWrap(CreateCommunity)) e.POST("/create_comm", ui.AmWrap(CreateCommunity), uiset...)
e.GET("/manage_comm", ui.AmWrap(ManageCommunities)) e.GET("/manage_comm", ui.AmWrap(ManageCommunities), uiset...)
e.POST("/attachment_upload", ui.AmWrap(AttachmentUpload)) e.POST("/attachment_upload", ui.AmWrap(AttachmentUpload), uiset...)
e.GET("/attachment/:post", ui.AmWrap(AttachmentSend)) e.GET("/attachment/:post", ui.AmWrap(AttachmentSend), uiset...)
e.POST("/__invite_send", ui.AmWrap(InviteSend)) e.POST("/__invite_send", ui.AmWrap(InviteSend), uiset...)
sysGroup := e.Group("/sysadmin") sysGroup := e.Group("/sysadmin", uiset...)
sysGroup.GET("", ui.AmWrap(SysAdminMenu)) sysGroup.GET("", ui.AmWrap(SysAdminMenu))
sysGroup.GET("/globals", ui.AmWrap(GlobalPropertiesForm)) sysGroup.GET("/globals", ui.AmWrap(GlobalPropertiesForm))
sysGroup.POST("/globals", ui.AmWrap(GlobalPropertiesSet)) sysGroup.POST("/globals", ui.AmWrap(GlobalPropertiesSet))
@@ -97,7 +99,9 @@ func setupEcho() *echo.Echo {
sysGroup.Match(GetAndPost, "/audit", ui.AmWrap(SystemAudit)) sysGroup.Match(GetAndPost, "/audit", ui.AmWrap(SystemAudit))
// community group // community group
commGroup := e.Group("/comm/:cid", ui.SetCommunity) uiset2 := make([]echo.MiddlewareFunc, len(uiset), len(uiset)+1)
copy(uiset2, uiset)
commGroup := e.Group("/comm/:cid", append(uiset2, ui.SetCommunity)...)
fn := ui.AmWrap(ShowCommunity) fn := ui.AmWrap(ShowCommunity)
commGroup.GET("", fn) commGroup.GET("", fn)
commGroup.GET("/profile", fn) commGroup.GET("/profile", fn)
@@ -220,6 +224,10 @@ func main() {
// Audit the startup // Audit the startup
database.AmStoreAudit(database.AmNewAudit(database.AuditStartup, 0, myIP.String(), database.AmStoreAudit(database.AmNewAudit(database.AuditStartup, 0, myIP.String(),
fmt.Sprintf("version=%s", config.AMSTERDAM_VERSION))) fmt.Sprintf("version=%s", config.AMSTERDAM_VERSION)))
defer func() {
// Audit the shutdown
database.AmStoreAudit(database.AmNewAudit(database.AuditShutdown, 0, myIP.String()))
}()
// Start server // Start server
go func() { go func() {
@@ -235,7 +243,4 @@ func main() {
if err := e.Shutdown(ctx); err != nil { if err := e.Shutdown(ctx); err != nil {
e.Logger.Fatal(err) e.Logger.Fatal(err)
} }
// Audit the shutdown
database.AmStoreAudit(database.AmNewAudit(database.AuditShutdown, 0, myIP.String()))
} }