This commit is contained in:
2023-07-10 10:13:57 +08:00
parent 2ef095c8e2
commit ce95e2f08f

View File

@@ -1,7 +1,6 @@
package main package main
import ( import (
"fmt"
"log" "log"
"net/http" "net/http"
"runtime" "runtime"
@@ -94,8 +93,9 @@ func main() {
r.HandleFunc("/img/{id}", routers.WebpGet).Methods("GET") r.HandleFunc("/img/{id}", routers.WebpGet).Methods("GET")
// 設定靜態資源 (前端) 位于dist目录下 // 設定靜態資源 (前端) 位于dist目录下
cacheTime := 7 * 24 * time.Hour //cacheTime := 7 * 24 * time.Hour
r.PathPrefix("/images/").Handler(http.FileServer(http.Dir("./data/"))).Headers("Cache-Control", fmt.Sprintf("max-age=%d", int(cacheTime.Seconds()))) r.PathPrefix("/images/").Handler(http.FileServer(http.Dir("./data/")))
//.Headers("Cache-Control", fmt.Sprintf("max-age=%d", int(cacheTime.Seconds())))
r.PathPrefix("/").Handler(http.FileServer(http.Dir("./dist/"))) r.PathPrefix("/").Handler(http.FileServer(http.Dir("./dist/")))
//// 設定靜態資源 (前端) 位于dist目录下, 并且为 图片和 js/css 设置缓存时间为7天 //// 設定靜態資源 (前端) 位于dist目录下, 并且为 图片和 js/css 设置缓存时间为7天