weird paths just redir to root

master
Bel LaPointe 2021-04-20 06:09:02 -05:00
parent 2e98bdff2d
commit 80becbb7a7
2 changed files with 35 additions and 7 deletions

View File

@ -47,6 +47,7 @@ func (s *Server) Routes() error {
return err
}
}
s.NotFound = s.gzip(s.index)
return nil
}
@ -79,6 +80,10 @@ func (s *Server) lang(w http.ResponseWriter, r *http.Request) {
`)
}
func (s *Server) toindex(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", http.StatusSeeOther)
}
func (s *Server) index(w http.ResponseWriter, r *http.Request) {
f, err := os.Open(path.Join(config.Root, "index.html"))
if err != nil {
@ -101,14 +106,37 @@ func (s *Server) phpProxy(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
} else {
log.Println("WOULD proxy", url.String(), r.URL.Path)
s.index(w, r)
s.toindex(w, r)
//proxy := httputil.NewSingleHostReverseProxy(url)
//proxy.ServeHTTP(w, r)
}
}
func (s *Server) static(w http.ResponseWriter, r *http.Request) {
s.fileServer.ServeHTTP(w, r)
if err := s._static(w, r); err != nil {
s.toindex(w, r)
}
}
func (s *Server) _static(w http.ResponseWriter, r *http.Request) error {
f, err := s.fileDir.Open(path.Clean(r.URL.Path))
if err != nil {
return err
}
defer f.Close()
info, err := f.Stat()
if err != nil {
return err
}
if info.IsDir() {
f, err = s.fileDir.Open(path.Join(r.URL.Path, "index.html"))
defer f.Close()
if err != nil {
return err
}
}
_, err = io.Copy(w, f)
return err
}
func (s *Server) gzip(h http.HandlerFunc) http.HandlerFunc {

View File

@ -10,7 +10,7 @@ import (
type Server struct {
*ajax.Ajax
*router.Router
fileServer http.Handler
fileDir http.Dir
}
func New() *Server {
@ -18,10 +18,10 @@ func New() *Server {
if err != nil {
panic(err)
}
fileServer := http.FileServer(http.Dir(config.Root))
fileDir := http.Dir(config.Root)
return &Server{
Ajax: ajax,
Router: router.New(),
fileServer: fileServer,
Ajax: ajax,
Router: router.New(),
fileDir: fileDir,
}
}