Add cache
This commit is contained in:
parent
e42ef9e4ba
commit
52f16c9966
4 changed files with 17 additions and 13 deletions
|
@ -1,9 +1,16 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/hertz-contrib/gzip"
|
||||
)
|
||||
|
||||
func CacheMiddleware() app.HandlerFunc {
|
||||
return func(ctx context.Context, c *app.RequestContext) {
|
||||
c.Header("Cache-Control", "public, max-age=604800, immutable")
|
||||
}
|
||||
}
|
||||
func (server *Server) setupMiddlewares() {
|
||||
server.Router.Use(gzip.Gzip(gzip.DefaultCompression))
|
||||
}
|
||||
|
|
|
@ -10,20 +10,18 @@ func (server *Server) setupRouter() {
|
|||
server.Router.GET("/", server.goDash)
|
||||
server.Router.GET("/ws", webSocket)
|
||||
|
||||
server.serveStatic("static")
|
||||
server.serveStatic("storage/icons")
|
||||
|
||||
server.Router.GET("/robots.txt", func(c context.Context, ctx *app.RequestContext) {
|
||||
ctx.File(TemplatesFolder + "/robots.txt")
|
||||
})
|
||||
server.Router.GET("/favicon.ico", func(c context.Context, ctx *app.RequestContext) {
|
||||
ctx.File("static/favicon/favicon.ico")
|
||||
})
|
||||
|
||||
server.Router.NoMethod(func(c context.Context, ctx *app.RequestContext) {
|
||||
ctx.Redirect(consts.StatusPermanentRedirect, []byte("/"))
|
||||
})
|
||||
server.Router.NoRoute(func(c context.Context, ctx *app.RequestContext) {
|
||||
ctx.Redirect(consts.StatusPermanentRedirect, []byte("/"))
|
||||
})
|
||||
|
||||
server.Router.Use(CacheMiddleware())
|
||||
server.serveStatic("static")
|
||||
server.serveStatic("storage/icons")
|
||||
|
||||
server.Router.GET("/robots.txt", func(c context.Context, ctx *app.RequestContext) {
|
||||
ctx.String(consts.StatusOK, "User-agent: *\nDisallow: /")
|
||||
})
|
||||
}
|
||||
|
|
|
@ -7,9 +7,10 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="description" content="A blazing fast start-page for services written in Go " />
|
||||
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/static/favicon/apple-touch-icon.png" />
|
||||
<link rel="icon" type="image/x-icon" href="/static/favicon/favicon.ico" />
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/static/favicon/favicon-32x32.png" />
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/static/favicon/favicon-16x16.png" />
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/static/favicon/apple-touch-icon.png" />
|
||||
<link rel="manifest" href="/static/favicon/site.webmanifest" />
|
||||
<style>
|
||||
.bookmark-link:hover .img {
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
User-agent: *
|
||||
Disallow: /
|
Loading…
Add table
Reference in a new issue