feat: refactor for using app config

This commit is contained in:
2025-05-25 16:22:28 +02:00
parent b95dcc6230
commit 07b9b94143
10 changed files with 120 additions and 153 deletions

View File

@ -7,6 +7,7 @@ import (
"os"
"gitea.local/admin/hspguard/internal/auth"
"gitea.local/admin/hspguard/internal/config"
imiddleware "gitea.local/admin/hspguard/internal/middleware"
"gitea.local/admin/hspguard/internal/oauth"
"gitea.local/admin/hspguard/internal/repository"
@ -20,9 +21,10 @@ type APIServer struct {
addr string
repo *repository.Queries
storage *storage.FileStorage
cfg *config.AppConfig
}
func NewAPIServer(addr string, db *repository.Queries, minio *storage.FileStorage) *APIServer {
func NewAPIServer(addr string, db *repository.Queries, minio *storage.FileStorage, cfg *config.AppConfig) *APIServer {
return &APIServer{
addr: addr,
repo: db,
@ -38,10 +40,10 @@ func (s *APIServer) Run() error {
// staticDir := http.Dir(filepath.Join(workDir, "static"))
// FileServer(router, "/static", staticDir)
oauthHandler := oauth.NewOAuthHandler(s.repo)
oauthHandler := oauth.NewOAuthHandler(s.repo, s.cfg)
router.Route("/api/v1", func(r chi.Router) {
r.Use(imiddleware.WithSkipper(imiddleware.AuthMiddleware, "/api/v1/login", "/api/v1/register", "/api/v1/oauth/token"))
r.Use(imiddleware.WithSkipper(imiddleware.AuthMiddleware(s.cfg), "/api/v1/login", "/api/v1/register", "/api/v1/oauth/token"))
userHandler := user.NewUserHandler(s.repo, s.storage)
userHandler.RegisterRoutes(r)
@ -52,8 +54,8 @@ func (s *APIServer) Run() error {
oauthHandler.RegisterRoutes(r)
})
router.Get("/.well-known/jwks.json", auth.WriteJWKS)
router.Get("/.well-known/openid-configuration", auth.OpenIdConfiguration)
router.Get("/.well-known/jwks.json", oauthHandler.WriteJWKS)
router.Get("/.well-known/openid-configuration", oauth.OpenIdConfiguration)
router.Get("/*", func(w http.ResponseWriter, r *http.Request) {
path := "./dist" + r.URL.Path