config file service 방식 변경

This commit is contained in:
2024-07-24 13:13:46 +09:00
parent 3eaad85453
commit 6f444e0187

View File

@ -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)
}