-
Notifications
You must be signed in to change notification settings - Fork 3
/
routes.go
78 lines (67 loc) · 2.43 KB
/
routes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/redirect/v2"
)
func startRoutes(app *fiber.App) {
app.Get("/favicon*", getFavicon)
app.Get("/img/icons/*", getFavicon)
app.Get("/healthz", getHealthz)
app.Get("/v1/clusterLinks", getClusterLinks)
app.Get("/v1/deploymentPieChart", getDeployments)
app.Get("/v1/deploymentTable", getDeploymentsTable)
app.Get("/v1/nodePieChart", getNodesPie)
app.Get("/v1/ingressTable", getRoutes)
app.Get("/v1/settings", getSettings)
app.Get("/v1/statefulSetPieChart", getStatefulSets)
app.Get("/v1/statefulSetTable", getStatefulSetsTable)
app.Get("/v1/table/inventory-flux-ignored", getFluxIgnored)
app.Get("/v1/nodeTable", getNodesTable)
// redirects to capture URL paths ending in "//"
// .. this sometimes seems to happen when browsers arrive via their "back" buttons/history
app.Get("//", func(c *fiber.Ctx) error {
return c.Redirect("/")
})
// match incoming queries prefixed with "//" and suggest a redirect
// EG a GET like "//foo" will get a 301 -> "/foo"
app.Use(redirect.New(redirect.Config{
Rules: map[string]string{
"//*": "/$1",
},
StatusCode: 301,
}))
// start the static asset serving
// NOTES:
// - the fiber.Config has "StrictRouting" "true" which ensures unmatched-paths (EG "//")
// won't go to static assets
// - ensure this is the last route declared
//
// read about fiber static settings: https://docs.gofiber.io/api/app#static
// Cache-Control tweaks
// read more https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching#defining_optimal_cache-control_policy
app.Static("/assets", "./frontend/dist/assets", fiber.Static{
Compress: true,
MaxAge: 3600,
CacheDuration: 60 * time.Minute,
})
app.Static("/css", "./frontend/dist/css", fiber.Static{
Compress: true,
MaxAge: 3600,
CacheDuration: 60 * time.Minute,
})
// potentially the js should be cached for less as its changed when we deploy new versions of lander
app.Static("/js", "./frontend/dist/js", fiber.Static{
Compress: true,
MaxAge: 300,
CacheDuration: 5 * time.Minute,
})
// NEVER cache /index.html
// currently fiber doesn't allow setting custom headers (EG: "no-cache", "no-store" or "expires 0")
// we can set "expires 1" and "max-age=1" however
app.Static("/", "./frontend/dist", fiber.Static{
Compress: true,
CacheDuration: 1 * time.Second,
MaxAge: 1,
})
}