2023-05-04 11:29:40 +08:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2023-05-25 18:09:32 +08:00
|
|
|
"adams549659584/go-proxy-bingai/api/helper"
|
2023-05-08 12:07:55 +08:00
|
|
|
"adams549659584/go-proxy-bingai/common"
|
2023-05-04 11:29:40 +08:00
|
|
|
"adams549659584/go-proxy-bingai/web"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func WebStatic(w http.ResponseWriter, r *http.Request) {
|
2023-05-15 15:19:09 +08:00
|
|
|
if _, ok := web.WEB_PATH_MAP[r.URL.Path]; ok || r.URL.Path == common.PROXY_WEB_PREFIX_PATH {
|
2023-05-08 12:07:55 +08:00
|
|
|
http.StripPrefix(common.PROXY_WEB_PREFIX_PATH, http.FileServer(web.GetWebFS())).ServeHTTP(w, r)
|
|
|
|
} else {
|
2023-05-25 18:09:32 +08:00
|
|
|
if !helper.CheckAuth(r) {
|
|
|
|
helper.UnauthorizedResult(w)
|
|
|
|
return
|
|
|
|
}
|
2023-05-08 12:07:55 +08:00
|
|
|
common.NewSingleHostReverseProxy(common.BING_URL).ServeHTTP(w, r)
|
|
|
|
}
|
2023-05-04 11:29:40 +08:00
|
|
|
}
|