fleet/ee/fleetd-chrome/server.go
Zach Wasserman 42b3e5602e
Fleetd for Chrome (#10281)
# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [x] Changes file added for user-visible changes in `changes/` or
`orbit/changes/`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
2023-03-16 09:01:10 -03:00

33 lines
730 B
Go

// This server can be used to serve the chrome extension during local
// development (though it is usually easier to use the "load unpacked" option in
// Chrome).
package main
import (
"log"
"net/http"
"regexp"
)
// The directory to serve.
var (
d = http.Dir(".")
fileserver = http.FileServer(d)
tFile = regexp.MustCompile(`\.crx$`)
)
func myfileserver(w http.ResponseWriter, r *http.Request) {
ruri := r.RequestURI
log.Println("request for: ", ruri)
if tFile.MatchString(ruri) {
w.Header().Set("Content-Type", "application/x-chrome-extension")
}
fileserver.ServeHTTP(w, r)
}
func main() {
http.HandleFunc("/", myfileserver)
log.Fatal(http.ListenAndServe("localhost:1337", nil)) //nolint:gosec
}