go:embed client/build

addon-dailer
liqiang 4 years ago
parent 392f3a0efc
commit 9f5ccdaf17

@ -1,6 +1,8 @@
package web package web
import ( import (
"embed"
"io/fs"
"net/http" "net/http"
"sync" "sync"
@ -12,6 +14,9 @@ import (
var log = _log.WithField("at", "web addon") var log = _log.WithField("at", "web addon")
//go:embed client/build
var assets embed.FS
func (web *WebAddon) echo(w http.ResponseWriter, r *http.Request) { func (web *WebAddon) echo(w http.ResponseWriter, r *http.Request) {
c, err := web.upgrader.Upgrade(w, r, nil) c, err := web.upgrader.Upgrade(w, r, nil)
if err != nil { if err != nil {
@ -51,7 +56,13 @@ func NewWebAddon() *WebAddon {
web.serverMux = new(http.ServeMux) web.serverMux = new(http.ServeMux)
web.serverMux.HandleFunc("/echo", web.echo) web.serverMux.HandleFunc("/echo", web.echo)
web.serverMux.Handle("/", http.FileServer(http.Dir("addon/web/client/build")))
// web.serverMux.Handle("/", http.FileServer(http.Dir("addon/web/client/build")))
fsys, err := fs.Sub(assets, "client/build")
if err != nil {
panic(err)
}
web.serverMux.Handle("/", http.FileServer(http.FS(fsys)))
web.server = &http.Server{Addr: web.addr, Handler: web.serverMux} web.server = &http.Server{Addr: web.addr, Handler: web.serverMux}
log = log.WithField("in", "WebAddon") log = log.WithField("in", "WebAddon")

@ -1,6 +1,6 @@
module github.com/lqqyt2423/go-mitmproxy module github.com/lqqyt2423/go-mitmproxy
go 1.15 go 1.16
require ( require (
github.com/andybalholm/brotli v1.0.1 github.com/andybalholm/brotli v1.0.1

Loading…
Cancel
Save