web addon config

addon-dailer
liqiang 4 years ago
parent 9f5ccdaf17
commit 657c5b382a

@ -1,4 +1,4 @@
all: mitmproxy dummycert all: mitmproxy
.PHONY: mitmproxy .PHONY: mitmproxy
mitmproxy: mitmproxy:

@ -36,41 +36,36 @@ func (web *WebAddon) echo(w http.ResponseWriter, r *http.Request) {
type WebAddon struct { type WebAddon struct {
addon.Base addon.Base
addr string
upgrader *websocket.Upgrader upgrader *websocket.Upgrader
serverMux *http.ServeMux
server *http.Server
conns []*concurrentConn conns []*concurrentConn
connsMu sync.RWMutex connsMu sync.RWMutex
} }
func NewWebAddon() *WebAddon { func NewWebAddon(addr string) *WebAddon {
web := new(WebAddon) web := new(WebAddon)
web.addr = ":9081"
web.upgrader = &websocket.Upgrader{ web.upgrader = &websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool { CheckOrigin: func(r *http.Request) bool {
return true return true
}, },
} }
web.serverMux = new(http.ServeMux) serverMux := new(http.ServeMux)
web.serverMux.HandleFunc("/echo", web.echo) serverMux.HandleFunc("/echo", web.echo)
// web.serverMux.Handle("/", http.FileServer(http.Dir("addon/web/client/build")))
fsys, err := fs.Sub(assets, "client/build") fsys, err := fs.Sub(assets, "client/build")
if err != nil { if err != nil {
panic(err) panic(err)
} }
web.serverMux.Handle("/", http.FileServer(http.FS(fsys))) serverMux.Handle("/", http.FileServer(http.FS(fsys)))
web.server = &http.Server{Addr: web.addr, Handler: web.serverMux} server := &http.Server{Addr: addr, Handler: serverMux}
log = log.WithField("in", "WebAddon") log = log.WithField("in", "WebAddon")
web.conns = make([]*concurrentConn, 0) web.conns = make([]*concurrentConn, 0)
go func() { go func() {
log.Infof("server start listen at %v\n", web.addr) log.Infof("web interface start listen at %v\n", addr)
err := web.server.ListenAndServe() err := server.ListenAndServe()
log.Error(err) log.Error(err)
}() }()

@ -12,6 +12,7 @@ import (
type Config struct { type Config struct {
addr string addr string
webAddr string
dump string // dump filename dump string // dump filename
dumpLevel int // dump level dumpLevel int // dump level
} }
@ -20,6 +21,7 @@ func loadConfig() *Config {
config := new(Config) config := new(Config)
flag.StringVar(&config.addr, "addr", ":9080", "proxy listen addr") flag.StringVar(&config.addr, "addr", ":9080", "proxy listen addr")
flag.StringVar(&config.webAddr, "web_addr", ":9081", "web interface listen addr")
flag.StringVar(&config.dump, "dump", "", "dump filename") flag.StringVar(&config.dump, "dump", "", "dump filename")
flag.IntVar(&config.dumpLevel, "dump_level", 0, "dump level: 0 - header, 1 - header + body") flag.IntVar(&config.dumpLevel, "dump_level", 0, "dump level: 0 - header, 1 - header + body")
flag.Parse() flag.Parse()
@ -53,7 +55,7 @@ func main() {
} }
p.AddAddon(&addon.Decoder{}) p.AddAddon(&addon.Decoder{})
p.AddAddon(web.NewWebAddon()) p.AddAddon(web.NewWebAddon(config.webAddr))
log.Fatal(p.Start()) log.Fatal(p.Start())
} }

Loading…
Cancel
Save