mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
add dev mode (PIXIVFE_DEV=1)
This commit is contained in:
@@ -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.")
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user