mirror of
				https://github.com/steveiliop56/tinyauth.git
				synced 2025-10-31 06:05:43 +00:00 
			
		
		
		
	 504a3b87b4
			
		
	
	504a3b87b4
	
	
	
		
			
			* wip: add middlewares * refactor: use context fom middleware in handlers * refactor: use controller approach in handlers * refactor: move oauth providers into services (non-working) * feat: create oauth broker service * refactor: use a boostrap service to bootstrap the app * refactor: split utils into smaller files * refactor: use more clear name for frontend assets * feat: allow customizability of resources dir * fix: fix typo in ui middleware * fix: validate resource file paths in ui middleware * refactor: move resource handling to a controller * feat: add some logging * fix: configure middlewares before groups * fix: use correct api path in login mutation * fix: coderabbit suggestions * fix: further coderabbit suggestions
		
			
				
	
	
		
			43 lines
		
	
	
		
			978 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			978 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package controller
 | |
| 
 | |
| import (
 | |
| 	"net/http"
 | |
| 
 | |
| 	"github.com/gin-gonic/gin"
 | |
| )
 | |
| 
 | |
| type ResourcesControllerConfig struct {
 | |
| 	ResourcesDir string
 | |
| }
 | |
| 
 | |
| type ResourcesController struct {
 | |
| 	Config     ResourcesControllerConfig
 | |
| 	Router     *gin.RouterGroup
 | |
| 	FileServer http.Handler
 | |
| }
 | |
| 
 | |
| func NewResourcesController(config ResourcesControllerConfig, router *gin.RouterGroup) *ResourcesController {
 | |
| 	fileServer := http.StripPrefix("/resources", http.FileServer(http.Dir(config.ResourcesDir)))
 | |
| 
 | |
| 	return &ResourcesController{
 | |
| 		Config:     config,
 | |
| 		Router:     router,
 | |
| 		FileServer: fileServer,
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func (controller *ResourcesController) SetupRoutes() {
 | |
| 	controller.Router.GET("/resources/*resource", controller.resourcesHandler)
 | |
| }
 | |
| 
 | |
| func (controller *ResourcesController) resourcesHandler(c *gin.Context) {
 | |
| 	if controller.Config.ResourcesDir == "" {
 | |
| 		c.JSON(404, gin.H{
 | |
| 			"status":  404,
 | |
| 			"message": "Resources not found",
 | |
| 		})
 | |
| 		return
 | |
| 	}
 | |
| 	controller.FileServer.ServeHTTP(c.Writer, c.Request)
 | |
| }
 |