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