亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

FileServe和Routing的更流暢配合

FileServe和Routing的更流暢配合

Go
皈依舞 2021-10-25 16:55:37
我有一個問題,我想在 FileServe 上提供我的主要 AngularJS(Yeoman 部署)應用程序文件夾,/但它會破壞我所有的路由器綁定。有什么辦法可以保留它們并保持我的路線完好無損?在下面的代碼中,我仍然需要去/app重新綁定其他文件夾,因為我不想過多地調整 Grunt 文件(還),所以為文件夾添加了一些額外的備份路徑綁定。func initializeRoutes() {    // Handle all requests by serving a file of the same name    fileHandler := http.FileServer(http.Dir(*clFlagStaticDirectory))    bowerFileHandler := http.FileServer(http.Dir("../bower_components"))    imagesFileHandler := http.FileServer(http.Dir("../app/images"))    scriptsFileHandler := http.FileServer(http.Dir("../app/scripts"))    stylesFileHandler := http.FileServer(http.Dir("../app/styles"))    viewsFileHandler := http.FileServer(http.Dir("../app/views"))    // Setup routes    mainRoute := mux.NewRouter()    mainRoute.StrictSlash(true)    // mainRoute.Handle("/", http.RedirectHandler("/static/", 302))    mainRoute.PathPrefix("/app").Handler(http.StripPrefix("/app", fileHandler))    mainRoute.PathPrefix("/app/bower_components").Handler(http.StripPrefix("/bower_components", bowerFileHandler))    mainRoute.PathPrefix("/bower_components").Handler(http.StripPrefix("/bower_components", bowerFileHandler))    mainRoute.PathPrefix("/images").Handler(http.StripPrefix("/images", imagesFileHandler))    mainRoute.PathPrefix("/scripts").Handler(http.StripPrefix("/scripts", scriptsFileHandler))    mainRoute.PathPrefix("/styles").Handler(http.StripPrefix("/styles", stylesFileHandler))    mainRoute.PathPrefix("/views").Handler(http.StripPrefix("/views", viewsFileHandler))    // Basic routes    // User routes    userRoute := mainRoute.PathPrefix("/users").Subrouter()    userRoute.Handle("/login", handler(userDoLogin)).Methods("POST")    userRoute.Handle("/logout", handler(userDoLogout)).Methods("GET")    userRoute.Handle("/forgot_password", handler(forgotPassword)).Methods("POST")}所以我的目標是/app作為我的/主要路徑,但保留我所有的 Mux 路由來贏得 FileServe。所以如果我有一個/app/users/login文件夾,它不會加載,而是會讓路由器獲勝。注意:我的服務純粹是結束HTTPS而不是結束HTTP。非常感謝!這打破了我的大腦,這是我在完全開始我的前端代碼之前需要弄清楚的最后一件事:)。
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 216 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號