Exemple #1
0
// Forward a request to the appropriate plugin
func pluginHandler(w http.ResponseWriter, r *http.Request) {
	pathVars := mux.Vars(r)
	pluginName := pathVars["plugin-name"]
	if endpoint, err := registry.GetPluginLocation(pluginName); err != nil {
		log.Println("No available Plugin Node for: " + pluginName)
		w.WriteHeader(http.StatusServiceUnavailable)
	} else {
		reverseProxy(endpoint, w, r)
	}
}
Exemple #2
0
// Serves a file from a plugin's resource directory
func servePluginResource(w http.ResponseWriter, r *http.Request) {
	LogRequest(r)
	pathVars := mux.Vars(r)
	pluginName := pathVars["plugin-name"]
	thePlugin, err := fserv.GetPluginData(pluginName)
	if err != nil {
		LogError(err)
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	pluginResourceDir := thePlugin.PluginDir
	theHandler := httpgzip.NewHandler(http.StripPrefix("/app/plugin/"+pluginName+"/resource/",
		http.FileServer(http.Dir(pluginResourceDir))))
	theHandler.ServeHTTP(w, r)
}