weird paths just redir to root
parent
2e98bdff2d
commit
80becbb7a7
|
|
@ -47,6 +47,7 @@ func (s *Server) Routes() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
s.NotFound = s.gzip(s.index)
|
||||||
return nil
|
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) {
|
func (s *Server) index(w http.ResponseWriter, r *http.Request) {
|
||||||
f, err := os.Open(path.Join(config.Root, "index.html"))
|
f, err := os.Open(path.Join(config.Root, "index.html"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -101,14 +106,37 @@ func (s *Server) phpProxy(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
} else {
|
} else {
|
||||||
log.Println("WOULD proxy", url.String(), r.URL.Path)
|
log.Println("WOULD proxy", url.String(), r.URL.Path)
|
||||||
s.index(w, r)
|
s.toindex(w, r)
|
||||||
//proxy := httputil.NewSingleHostReverseProxy(url)
|
//proxy := httputil.NewSingleHostReverseProxy(url)
|
||||||
//proxy.ServeHTTP(w, r)
|
//proxy.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) static(w http.ResponseWriter, r *http.Request) {
|
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 {
|
func (s *Server) gzip(h http.HandlerFunc) http.HandlerFunc {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
type Server struct {
|
type Server struct {
|
||||||
*ajax.Ajax
|
*ajax.Ajax
|
||||||
*router.Router
|
*router.Router
|
||||||
fileServer http.Handler
|
fileDir http.Dir
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *Server {
|
func New() *Server {
|
||||||
|
|
@ -18,10 +18,10 @@ func New() *Server {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
fileServer := http.FileServer(http.Dir(config.Root))
|
fileDir := http.Dir(config.Root)
|
||||||
return &Server{
|
return &Server{
|
||||||
Ajax: ajax,
|
Ajax: ajax,
|
||||||
Router: router.New(),
|
Router: router.New(),
|
||||||
fileServer: fileServer,
|
fileDir: fileDir,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue