From d0308e6538a581d8b6f305a4538a670961243bb9 Mon Sep 17 00:00:00 2001 From: Patrick Peng Sun Date: Sat, 20 May 2017 18:18:45 +1000 Subject: [PATCH] hook upload handler and add configurable path for augnlar2app --- main.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 763e8b2..15e6645 100644 --- a/main.go +++ b/main.go @@ -8,10 +8,13 @@ import ( //PathsConfig all system available pathes type PathsConfig struct { CRMAttachment string `json:"crm_attachmeng"` + Angular2App string `json:"angular2_app"` } //GlobalPath all global pathes configurations -var GlobalPath = PathsConfig{"/tmp/"} +var GlobalPath = PathsConfig{ + "/tmp/", + "/mnt/data/workspace/angular.ts/wechat/ng2-admin/dist/"} func main() { err := readConfig() //wechat API config @@ -27,10 +30,8 @@ func main() { log.Fatal("unable to read crm_config.json, program quit") } - //fs := http.FileServer(http.Dir("/mnt/data/workspace/angular.ts/ng2-admin/dist")) - fs := http.FileServer(http.Dir("/mnt/data/workspace/angular.ts/wechat/ng2-admin/dist")) - //http.Handle("/test", http.StripPrefix("/test", fs)) - http.Handle("/", fs) + setupRootFileServer() + //setup handler //http.HandleFunc("/", webrootHandler) http.HandleFunc("/api", apiV1Main) @@ -38,3 +39,15 @@ func main() { http.HandleFunc("/crmfiles/", crmAttachmentHandler) http.ListenAndServe(":65500", nil) } + +func setupRootFileServer() { + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + http.ServeFile(w, r, GlobalPath.Angular2App+r.URL.Path[1:]) + }) + + //fs := http.FileServer(http.Dir("/mnt/data/workspace/angular.ts/ng2-admin/dist")) + //http.Handle("/test", http.StripPrefix("/test", fs)) + + //fs := http.FileServer(http.Dir("/mnt/data/workspace/angular.ts/wechat/ng2-admin/dist")) + //http.Handle("/", fs) +}