func connectToVeil(t *testing.T) *rpc.Client {
	c, err := myrpc.Dial("tcp", os.Getenv("VEIL_LISTENER"))
	if err != nil {
		t.Fatal(err)
	}
	return c
}
Esempio n. 2
0
func main() {
	c, err := myrpc.Dial("tcp", checkEnv("VEIL_LISTENER"))
	check(err)
	h := handlers.New(&handlers.H{C: c})
	r := mux.NewRouter()
	r.HandleFunc("/api/version", h.Version).Methods("GET")
	r.HandleFunc("/api/payloads", h.Payloads).Methods("GET")
	r.HandleFunc("/api/options", h.PayloadOptions).Methods("GET")
	r.HandleFunc("/api/generate", h.Generate).Methods("POST")
	n := negroni.New()
	n.Use(negroni.NewLogger())
	n.Use(negroni.NewRecovery())
	n.Use(negroni.NewStatic(http.Dir(checkEnv("VEIL_OUTPUT_DIR"))))
	n.Use(auth.Basic(checkEnv("ADMIN_USER"), checkEnv("ADMIN_PASS")))
	n.Use(negroni.NewStatic(http.Dir("public")))
	n.Use(negroni.HandlerFunc(func(w http.ResponseWriter, req *http.Request, next http.HandlerFunc) {
		if req.Method != "POST" {
			next(w, req)
			return
		}
		if !strings.Contains(req.Header.Get("content-type"), "application/json") {
			h.JSON400(w, errors.New("Content-Type must be application/json"))
			return
		}
		next(w, req)
	}))
	n.UseHandler(r)
	n.Run(checkEnv("SERVER_LISTENER"))
}