fix: build
This commit is contained in:
@@ -13,6 +13,7 @@ type cliParams struct {
|
||||
ListenAddr string
|
||||
ListenPort int
|
||||
DataDir string
|
||||
StaticDir string
|
||||
SettingsFile string
|
||||
}
|
||||
|
||||
@@ -41,5 +42,16 @@ func (p *cliParams) Validate() error {
|
||||
return fmt.Errorf("failed to create images directory: %w", err)
|
||||
}
|
||||
|
||||
// Validate Static Directory
|
||||
if p.StaticDir != "" {
|
||||
info, err := os.Stat(p.StaticDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to access static directory: %w", err)
|
||||
}
|
||||
if !info.IsDir() {
|
||||
return fmt.Errorf("static directory is not a directory: %s", p.StaticDir)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -16,12 +16,14 @@ var (
|
||||
ListenAddr: getEnvOrDefault("LISTEN", "localhost"),
|
||||
ListenPort: getEnvIntOrDefault("PORT", 8080),
|
||||
DataDir: getEnvOrDefault("DATA_DIR", "./data"),
|
||||
StaticDir: getEnvOrDefault("STATIC_DIR", ""),
|
||||
}
|
||||
rootCmd = &cobra.Command{Use: "aethera"}
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().StringVar(¶ms.DataDir, "data-dir", params.DataDir, "Directory to store generated images (env: AETHERA_DATA_DIR)")
|
||||
rootCmd.PersistentFlags().StringVar(¶ms.StaticDir, "static-dir", params.StaticDir, "Directory to serve static frontend files from instead of embedded assets (env: AETHERA_STATIC_DIR)")
|
||||
rootCmd.PersistentFlags().StringVar(¶ms.ListenAddr, "listen", params.ListenAddr, "Address to listen on (env: AETHERA_LISTEN)")
|
||||
rootCmd.PersistentFlags().IntVar(¶ms.ListenPort, "port", params.ListenPort, "Port to listen on (env: AETHERA_PORT)")
|
||||
}
|
||||
@@ -40,7 +42,7 @@ func main() {
|
||||
|
||||
// Start Server
|
||||
rootCmd.Run = func(cmd *cobra.Command, args []string) {
|
||||
server.StartServer(fileStore, params.DataDir, params.ListenAddr, params.ListenPort)
|
||||
server.StartServer(fileStore, params.DataDir, params.StaticDir, params.ListenAddr, params.ListenPort)
|
||||
}
|
||||
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
|
||||
@@ -13,19 +13,24 @@ import (
|
||||
"reichard.io/aethera/web"
|
||||
)
|
||||
|
||||
func StartServer(settingsStore store.Store, dataDir, listenAddress string, listenPort int) {
|
||||
func StartServer(settingsStore store.Store, dataDir, staticDir, listenAddress string, listenPort int) {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
// Create API Instance - use settingsStore as the unified store for both settings and chat
|
||||
logger := logrus.New()
|
||||
api := api.New(settingsStore, dataDir, logger)
|
||||
|
||||
// Serve embedded static assets
|
||||
staticFS, err := fs.Sub(web.Assets, "static")
|
||||
if err != nil {
|
||||
logrus.Fatal("Failed to create static filesystem: ", err)
|
||||
// Serve Static Assets
|
||||
if staticDir != "" {
|
||||
logrus.Infof("Serving static assets from directory: %s", staticDir)
|
||||
mux.Handle("GET /", http.FileServer(http.Dir(staticDir)))
|
||||
} else {
|
||||
staticFS, err := fs.Sub(web.Assets, "static")
|
||||
if err != nil {
|
||||
logrus.Fatal("Failed to create static filesystem: ", err)
|
||||
}
|
||||
mux.Handle("GET /", http.FileServer(http.FS(staticFS)))
|
||||
}
|
||||
mux.Handle("GET /", http.FileServer(http.FS(staticFS)))
|
||||
|
||||
// Serve Generated Data
|
||||
genFS := http.FileServer(http.Dir(path.Join(dataDir, "generated")))
|
||||
|
||||
Reference in New Issue
Block a user