Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 304 cache after update #49

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion route/static_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package route

import (
"net/http"
"os"
"path/filepath"
"time"

"github.com/IceWhaleTech/CasaOS-Gateway/service"
"github.com/labstack/echo/v4"
Expand All @@ -12,6 +15,8 @@ type StaticRoute struct {
state *service.State
}

var startTime = time.Now()

var RouteCache = make(map[string]string)

func NewStaticRoute(state *service.State) *StaticRoute {
Expand All @@ -35,8 +40,18 @@ func (s *StaticRoute) GetRoute() http.Handler {
}
})

// serve /index.html to sovle 304 cache problem by 'If-Modified-Since: Wed, 21 Oct 2015 07:28:00 GMT' from web browser
e.GET("/", func(ctx echo.Context) error {
f, err := os.Open(filepath.Join(s.state.GetWWWPath(), "index.html"))
if err != nil {
return err
}
defer f.Close()
http.ServeContent(ctx.Response(), ctx.Request(), "index.html", startTime, f)
return nil
})

e.Static("/", s.state.GetWWWPath())

return e
}

Loading