我有一個問題,我想在 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 回答
- 0 關注
- 216 瀏覽
添加回答
舉報
0/150
提交
取消