mirror of
https://github.com/renorris/openfsd
synced 2026-03-22 06:25:35 +08:00
Embed static assets and support external configuration
This commit is contained in:
@@ -8,10 +8,9 @@ import (
|
||||
type ServerConfig struct {
|
||||
ListenAddr string `env:"LISTEN_ADDR, default=:8000"` // HTTP listen address
|
||||
|
||||
DatabaseDriver string `env:"DATABASE_DRIVER, default=sqlite"` // Golang sql database driver name
|
||||
DatabaseSourceName string `env:"DATABASE_SOURCE_NAME, default=:memory:"` // Golang sql database source name
|
||||
DatabaseAutoMigrate bool `env:"DATABASE_AUTO_MIGRATE, default=false"` // Whether to automatically run database migrations on startup
|
||||
DatabaseMaxConns int `env:"DATABASE_MAX_CONNS, default=1"` // Max number of database connections
|
||||
DatabaseDriver string `env:"DATABASE_DRIVER, default=sqlite"` // Golang sql database driver name
|
||||
DatabaseSourceName string `env:"DATABASE_SOURCE_NAME, default=:memory:"` // Golang sql database source name
|
||||
DatabaseMaxConns int `env:"DATABASE_MAX_CONNS, default=1"` // Max number of database connections
|
||||
|
||||
FsdHttpServiceAddress string `env:"FSD_HTTP_SERVICE_ADDRESS, required"` // HTTP address to talk to the FSD http service
|
||||
}
|
||||
|
||||
@@ -9,10 +9,6 @@ import (
|
||||
func main() {
|
||||
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||
|
||||
os.Setenv("DATABASE_DRIVER", "sqlite")
|
||||
os.Setenv("DATABASE_SOURCE_NAME", "../test.db")
|
||||
os.Setenv("FSD_HTTP_SERVICE_ADDRESS", "http://localhost:13618")
|
||||
|
||||
server, err := NewDefaultServer(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
//go:embed static/*
|
||||
var staticFS embed.FS
|
||||
|
||||
func (s *Server) setupRoutes() (e *gin.Engine) {
|
||||
e = gin.New()
|
||||
e.Use(gin.Recovery())
|
||||
@@ -29,7 +35,11 @@ func (s *Server) setupRoutes() (e *gin.Engine) {
|
||||
s.setupFrontendRoutes(e.Group(""))
|
||||
|
||||
// Serve static files
|
||||
e.Static("/static", "./static")
|
||||
subFS, err := fs.Sub(staticFS, "static")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
e.StaticFS("/static", http.FS(subFS))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user