模型安全加载

This commit is contained in:
2023-07-10 08:32:51 +08:00
parent 30de6b2547
commit 2ef095c8e2
2 changed files with 34 additions and 37 deletions

16
main.go
View File

@@ -93,12 +93,18 @@ func main() {
r.HandleFunc("/img/{id}", routers.WebpGet).Methods("GET")
// 設定靜態資源 (前端) 位于dist目录下, 并且为 图片和 js/css 设置缓存时间为7天
// 設定靜態資源 (前端) 位于dist目录下
cacheTime := 7 * 24 * time.Hour
r.PathPrefix("/images/").Handler(http.StripPrefix("/images/", http.FileServer(http.Dir("./data/")))).Headers("Cache-Control", fmt.Sprintf("max-age=%d", int(cacheTime.Seconds()))).Methods("GET")
r.PathPrefix("/static/").Handler(http.StripPrefix("/", http.FileServer(http.Dir("./dist/static/")))).Headers("Cache-Control", fmt.Sprintf("max-age=%d", int(cacheTime.Seconds()))).Methods("GET")
r.PathPrefix("/favicon.ico").Handler(http.StripPrefix("/", http.FileServer(http.Dir("./dist/favicon.ico")))).Headers("Cache-Control", fmt.Sprintf("max-age=%d", int(cacheTime.Seconds()))).Methods("GET")
r.PathPrefix("/").Handler(http.StripPrefix("/", http.FileServer(http.Dir("./dist/")))).Methods("GET")
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/")))
//// 設定靜態資源 (前端) 位于dist目录下, 并且为 图片和 js/css 设置缓存时间为7天
//cacheTime := 7 * 24 * time.Hour
//r.PathPrefix("/images/").Handler(http.StripPrefix("/images/", http.FileServer(http.Dir("./data/images/")))).Headers("Cache-Control", fmt.Sprintf("max-age=%d", int(cacheTime.Seconds()))).Methods("GET")
//r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./dist/static/")))).Headers("Cache-Control", fmt.Sprintf("max-age=%d", int(cacheTime.Seconds()))).Methods("GET")
//r.PathPrefix("/favicon.ico").Handler(http.StripPrefix("/", http.FileServer(http.Dir("./dist/favicon.ico")))).Headers("Cache-Control", fmt.Sprintf("max-age=%d", int(cacheTime.Seconds()))).Methods("GET")
//r.PathPrefix("/").Handler(http.StripPrefix("/", http.FileServer(http.Dir("./dist/")))).Methods("GET")
//r.PathPrefix("/").Handler(http.StripPrefix("/", http.FileServer(http.Dir("./dist/")))).Headers("Cache-Control", fmt.Sprintf("max-age=%d", int(cacheTime.Seconds()))).Methods("GET")
log.Println("Web Server is running on http://localhost:8080")
if err := http.ListenAndServe(":8080", r); err != nil {