Browse Source

fix livereload middleware (livereload.js, env issue)

tags/v0.9.0
jimzhan 9 years ago
parent
commit
8020112ceb
1 changed files with 2 additions and 9 deletions
  1. +2
    -9
      livereload/middleware.go

+ 2
- 9
livereload/middleware.go View File

"net/http" "net/http"
"regexp" "regexp"
"strings" "strings"

"github.com/Sirupsen/logrus"
"github.com/goanywhere/env"
) )


type writer struct { type writer struct {
} }


func (self *writer) addJavaScript(data []byte) []byte { func (self *writer) addJavaScript(data []byte) []byte {
javascript := fmt.Sprintf(`<script src="//%s%s"></script>
javascript := fmt.Sprintf(`<script defer src="//%s%s"></script>
</head>`, self.host, URL.JavaScript) </head>`, self.host, URL.JavaScript)
logrus.Infof("JS: %s", javascript)
return regexp.MustCompile(`</head>`).ReplaceAll(data, []byte(javascript)) return regexp.MustCompile(`</head>`).ReplaceAll(data, []byte(javascript))
} }


} }


func Middleware(next http.Handler) http.Handler { func Middleware(next http.Handler) http.Handler {
// ONLY run this under debug mode.
if !env.Bool("DEBUG") {
return next
}
Start() Start()

fn := func(w http.ResponseWriter, r *http.Request) { fn := func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == URL.WebSocket { if r.URL.Path == URL.WebSocket {
ServeWebSocket(w, r) ServeWebSocket(w, r)

Loading…
Cancel
Save