add dev mode (PIXIVFE_DEV=1)

This commit is contained in:
iacore
2024-02-10 13:54:09 +00:00
parent bbabed712e
commit 974e360704
2 changed files with 28 additions and 18 deletions
+6 -2
View File
@@ -27,11 +27,15 @@ type ServerConfig struct {
AcceptLanguage string
RequestLimit int
StartingTime string
Version string
StartingTime string
Version string
InDevelopment bool
}
func (s *ServerConfig) InitializeConfig() error {
_, hasDev := os.LookupEnv("PIXIVFE_DEV")
s.InDevelopment = hasDev
token, hasToken := os.LookupEnv("PIXIVFE_TOKEN")
if !hasToken {
log.Fatalln("PIXIVFE_TOKEN is required, but was not set.")
+22 -16
View File
@@ -36,6 +36,9 @@ func main() {
config.GlobalServerConfig.InitializeConfig()
engine := jet.New("./views", ".jet.html")
if config.GlobalServerConfig.InDevelopment {
engine.Reload(true)
}
engine.AddFuncMap(serve.GetTemplateFunctions())
@@ -79,25 +82,28 @@ func main() {
},
))
server.Use(cache.New(
cache.Config{
Next: func(c *fiber.Ctx) bool {
resp_code := c.Response().StatusCode()
if resp_code < 200 || resp_code >= 300 {
return true
}
if !config.GlobalServerConfig.InDevelopment {
server.Use(cache.New(
cache.Config{
Next: func(c *fiber.Ctx) bool {
resp_code := c.Response().StatusCode()
if resp_code < 200 || resp_code >= 300 {
return true
}
// Disable cache for settings page
return strings.Contains(c.Path(), "/settings") || c.Path() == "/"
},
Expiration: 5 * time.Minute,
CacheControl: true,
// Disable cache for settings page
return strings.Contains(c.Path(), "/settings") || c.Path() == "/"
},
Expiration: 5 * time.Minute,
CacheControl: true,
KeyGenerator: func(c *fiber.Ctx) string {
return utils.CopyString(c.OriginalURL())
KeyGenerator: func(c *fiber.Ctx) string {
return utils.CopyString(c.OriginalURL())
},
},
},
))
))
}
server.Use(recover.New())
server.Use(compress.New(compress.Config{