Added static serving

This commit is contained in:
2026-03-30 20:34:27 +02:00
parent 42f9b974b2
commit a8a2b3f95a
5 changed files with 90 additions and 7 deletions
+20 -4
View File
@@ -13,10 +13,13 @@ type GlobalConfig struct {
}
type SiteConfig struct {
Repo string `yaml:"repo"`
Owner string `yaml:"owner"`
Branch string `yaml:"branch"`
Domain string `yaml:"domain"`
Name string `yaml:"name"`
Repo string `yaml:"repo"`
Owner string `yaml:"owner"`
Branch string `yaml:"branch"`
Domain string `yaml:"domain"`
SPA bool `yaml:"spa"`
NotFoundFile string `yaml:"not_found_file"`
}
type Config struct {
@@ -44,6 +47,9 @@ func validateConfig(config *Config) error {
return &Error{Field: "global.storage_path", Message: "Storage path is required"}
}
for i, site := range config.Sites {
if site.Name == "" {
return &Error{Field: "sites[" + string(i) + "].name", Message: "Name is required"}
}
if site.Repo == "" {
return &Error{Field: "sites[" + string(i) + "].repo", Message: "Repo is required"}
}
@@ -60,6 +66,14 @@ func validateConfig(config *Config) error {
return nil
}
func applyDefaults(config *Config) {
for i := range config.Sites {
if config.Sites[i].NotFoundFile == "" {
config.Sites[i].NotFoundFile = "404.html"
}
}
}
func Load(path string) (*Config, error) {
f, err := os.ReadFile(path)
if err != nil {
@@ -72,6 +86,8 @@ func Load(path string) (*Config, error) {
return nil, err
}
applyDefaults(&config)
err = validateConfig(&config)
if err != nil {
return nil, err
+1 -1
View File
@@ -6,7 +6,7 @@ import (
)
func Setup(app *fiber.App) {
app.Use(func(c fiber.Ctx) error {
app.Use("/api", func(c fiber.Ctx) error {
c.Set("Content-Type", "application/json")
return c.Next()
})