diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/server/main.go | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/cmd/server/main.go b/cmd/server/main.go index f58366f..4942ac3 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -72,16 +72,6 @@ func main() { r := router.New() r.GET("/static/{filepath:*}", ext.FileServer(img.StaticFS, "static/")) - authMiddleware := ext.NewAuthMiddleware(hexKey, logger.WithField("context", "auth")) - logMiddleware := ext.NewLogMiddleare(logger.WithField("context", "http")) - - extRouter := ext.NewRouter(r) - extRouter.AddMiddleware(logMiddleware.HTTP) - extRouter.AddMiddleware(authMiddleware.LoggedIn) - extRouter.AddMiddleware(ext.HTML) - - scheduler := worker.NewScheduler(*schedulerCount) - // repository var ( userRepository = sql.NewUserRepository(db) @@ -90,12 +80,24 @@ func main() { mediaRepository = sql.NewMediaRepository(db) ) - //TODO: remove later - userRepository.EnsureAdmin(context.Background()) + // middleware + var ( + authMiddleware = ext.NewAuthMiddleware(hexKey, logger.WithField("context", "auth")) + logMiddleware = ext.NewLogMiddleare(logger.WithField("context", "http")) + initialMiddleware = ext.NewInitialSetupMiddleware(userRepository) + ) + + extRouter := ext.NewRouter(r) + extRouter.AddMiddleware(ext.HTML) + extRouter.AddMiddleware(initialMiddleware.Check) + extRouter.AddMiddleware(authMiddleware.LoggedIn) + extRouter.AddMiddleware(logMiddleware.HTTP) + + scheduler := worker.NewScheduler(*schedulerCount) // controller var ( - userController = auth.NewController(userRepository, hexKey) + userController = auth.NewController(userRepository, userRepository, hexKey) fileSystemController = filesystem.NewController(fileSystemRepository) ) |