diff --git a/server/http_handler.go b/server/http_handler.go index 7c4ae8c..e6df906 100644 --- a/server/http_handler.go +++ b/server/http_handler.go @@ -93,24 +93,27 @@ func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string // config는 접근하기 편하게 단축 경로 제공 serveMux.HandleFunc("/config/", func(w http.ResponseWriter, r *http.Request) { logger.Println("config url.path :", r.URL.Path) - h := md5.New() - h.Write([]byte(r.URL.Path)) - at := hex.EncodeToString(h.Sum(nil)) + testhash := md5.New() + testhash.Write([]byte(r.URL.Path)) + at := hex.EncodeToString(testhash.Sum(nil)) hash := r.Header.Get("As-X-UrlHash") logger.Println("config at = hash :", at, hash) if at == hash { urlpath := strings.TrimPrefix(r.URL.Path, "/config/") dir := path.Dir(urlpath) file := path.Base(urlpath) - dest := fmt.Sprintf("%s/config/%s", dir, file) - logger.Println("config dest :", dest) - r2 := new(http.Request) - *r2 = *r - r2.URL = new(url.URL) - *r2.URL = *r.URL - r2.URL.Path = dest - r2.URL.RawPath = dest - fsx.ServeHTTP(w, r2) + sourceFile := path.Join(h.deployPath, dir, "config", file) + logger.Println("config dest :", sourceFile) + bt, err := os.ReadFile(sourceFile) + if err != nil && !os.IsExist(err) { + logger.Println("config file is missing :", sourceFile) + w.WriteHeader(http.StatusNotFound) + } else { + if _, err = w.Write(bt); err != nil { + logger.Println("config write failed :", err) + w.WriteHeader(http.StatusInternalServerError) + } + } } else { http.NotFound(w, r) }