feat: Implement NewRouter function for serving frontend static files

This commit is contained in:
Wikid82
2025-11-19 21:37:06 -05:00
parent 619c6f2129
commit fd6987e4a1
+21
View File
@@ -0,0 +1,21 @@
package server
import (
"github.com/gin-gonic/gin"
)
// NewRouter creates a new Gin router with frontend static file serving.
func NewRouter(frontendDir string) *gin.Engine {
router := gin.Default()
// Serve frontend static files
if frontendDir != "" {
router.Static("/assets", frontendDir+"/assets")
router.StaticFile("/", frontendDir+"/index.html")
router.NoRoute(func(c *gin.Context) {
c.File(frontendDir + "/index.html")
})
}
return router
}