mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
Static fileserver improvements, optional admin panel route (#100)
* better asset serving, optional admin panel route * linting
This commit is contained in:
@@ -24,7 +24,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/gin-contrib/static"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/api"
|
||||
@@ -93,7 +92,11 @@ func (m *Module) Route(s router.Router) error {
|
||||
return fmt.Errorf("error getting current working directory: %s", err)
|
||||
}
|
||||
assetPath := filepath.Join(cwd, m.config.TemplateConfig.AssetBaseDir)
|
||||
s.AttachMiddleware(static.Serve("/assets", static.LocalFile(assetPath, false)))
|
||||
s.AttachStaticFS("/assets", FileSystem{http.Dir(assetPath)})
|
||||
|
||||
// Admin panel route, if it exists
|
||||
adminPath := filepath.Join(cwd, m.config.TemplateConfig.AssetBaseDir, "/admin")
|
||||
s.AttachStaticFS("/admin", FileSystem{http.Dir(adminPath)})
|
||||
|
||||
// serve front-page
|
||||
s.AttachHandler(http.MethodGet, "/", m.baseHandler)
|
||||
@@ -101,9 +104,5 @@ func (m *Module) Route(s router.Router) error {
|
||||
// 404 handler
|
||||
s.AttachNoRouteHandler(m.NotFoundHandler)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("error setting router FuncMap: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user