mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 00:55:32 +00:00
Changed file extensions + single issue view
This commit is contained in:
8
server/helpers.go
Normal file
8
server/helpers.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package server
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
|
||||
func CacheFunc(c *fiber.Ctx) bool {
|
||||
return c.Query("noCache") == "true" || c.Response().StatusCode() != fiber.StatusOK
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ const (
|
||||
REQUEST_TIMEOUT = 8 * time.Second
|
||||
SERVER_TIMEOUT = 8 * time.Second
|
||||
|
||||
CACHE_TIME = 24 * time.Hour
|
||||
|
||||
STATIC_PREFIX = "/assets"
|
||||
)
|
||||
|
||||
@@ -99,18 +101,27 @@ func (s *Server) Watcher() error {
|
||||
func (s *Server) Start() {
|
||||
s.engine.Reload()
|
||||
|
||||
if s.cache != nil {
|
||||
s.cache.Close()
|
||||
}
|
||||
|
||||
s.cache = memory.New(memory.Config{
|
||||
GCInterval: 30 * time.Second,
|
||||
})
|
||||
|
||||
srv := fiber.New(fiber.Config{
|
||||
AppName: s.Config.Address,
|
||||
CaseSensitive: false,
|
||||
StrictRouting: true,
|
||||
EnableIPValidation: true,
|
||||
EnablePrintRoutes: s.Config.Debug,
|
||||
AppName: s.Config.Address,
|
||||
CaseSensitive: false,
|
||||
|
||||
// INFO: This is a bit of an issue, since this treats /foo and /foo/ as different routes:
|
||||
// Maybe we turn that behavior permanently off and differentiate HTMX from "normal" reuqests only by headers.
|
||||
StrictRouting: true,
|
||||
|
||||
EnablePrintRoutes: s.Config.Debug,
|
||||
|
||||
// TODO: Error handler, which sadly, is global:
|
||||
ErrorHandler: fiber.DefaultErrorHandler,
|
||||
|
||||
// WARNING: The app must be run in a console, since this uses environment variables:
|
||||
// It is not trivial to turn this on, since we need to mark goroutines that can be started only once.
|
||||
// Prefork: true,
|
||||
@@ -136,20 +147,15 @@ func (s *Server) Start() {
|
||||
// INFO: Maybe fiber does this already?
|
||||
if s.Config.Debug {
|
||||
srv.Use(cache.New(cache.Config{
|
||||
Next: func(c *fiber.Ctx) bool {
|
||||
return c.Query("noCache") == "true"
|
||||
},
|
||||
Expiration: 30 * time.Minute,
|
||||
Next: CacheFunc,
|
||||
Expiration: CACHE_TIME,
|
||||
CacheControl: false,
|
||||
Storage: s.cache,
|
||||
}))
|
||||
} else {
|
||||
srv.Use(cache.New(cache.Config{
|
||||
Next: func(c *fiber.Ctx) bool {
|
||||
// We do not cache error responses
|
||||
return c.Query("noCache") == "true" || c.Response().StatusCode() != fiber.StatusOK
|
||||
},
|
||||
Expiration: 30 * time.Minute,
|
||||
Next: CacheFunc,
|
||||
Expiration: CACHE_TIME,
|
||||
CacheControl: true,
|
||||
Storage: s.cache,
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user