1
1
package main
2
2
3
3
import (
4
+ "encoding/base64"
4
5
"io"
5
6
"log"
6
7
"net"
7
8
"net/http"
8
9
"net/http/httputil"
9
10
"net/url"
11
+ "path/filepath"
10
12
"strings"
11
13
12
- "encoding/base64"
13
-
14
14
"github.com/go-martini/martini"
15
15
"github.com/martini-contrib/oauth2"
16
16
"github.com/martini-contrib/sessions"
17
- "path/filepath"
18
17
)
19
18
20
19
type Server struct {
@@ -58,11 +57,14 @@ func (s *Server) Run() error {
58
57
59
58
backendsFor := make (map [string ][]Backend )
60
59
backendIndex := make ([]string , len (s .Conf .Proxies ))
60
+ rawPaths := make ([]string , len (s .Conf .Proxies ))
61
61
62
62
for i := range s .Conf .Proxies {
63
63
p := s .Conf .Proxies [i ]
64
64
65
+ rawPath := ""
65
66
if strings .HasSuffix (p .Path , "/" ) == false {
67
+ rawPath = p .Path
66
68
p .Path += "/"
67
69
}
68
70
strip_path := p .Path
@@ -82,17 +84,24 @@ func (s *Server) Run() error {
82
84
StripPath : strip_path ,
83
85
})
84
86
backendIndex [i ] = p .Path
87
+ rawPaths [i ] = rawPath
85
88
log .Printf ("register proxy host:%s path:%s dest:%s strip_path:%v" , p .Host , strip_path , u .String (), p .Strip )
86
89
}
87
90
88
91
registered := make (map [string ]bool )
89
- for _ , path := range backendIndex {
92
+ for i , path := range backendIndex {
90
93
if registered [path ] {
91
94
continue
92
95
}
93
96
proxy := newVirtualHostReverseProxy (backendsFor [path ])
94
97
m .Any (path , proxyHandleWrapper (proxy ))
95
98
registered [path ] = true
99
+ rawPath := rawPaths [i ]
100
+ if rawPath != "" {
101
+ m .Get (rawPath , func (w http.ResponseWriter , r * http.Request ) {
102
+ http .Redirect (w , r , rawPath + "/" , http .StatusFound )
103
+ })
104
+ }
96
105
}
97
106
98
107
path , err := filepath .Abs (s .Conf .Htdocs )
0 commit comments