Example #1
0
func serveDashboardJs(res http.ResponseWriter, req *http.Request, conf *Config) {
	file := filepath.Join(conf.StaticPath, "assets", filepath.Base(req.URL.Path))
	f, err := os.Open(file)
	if err != nil {
		fmt.Println(err)
		res.WriteHeader(500)
		return
	}
	defer f.Close()
	fi, err := f.Stat()
	if err != nil {
		fmt.Println(err)
		return
	}

	jsConf := strings.NewReader(fmt.Sprintf(`
    window.DashboardConfig = {
      API_SERVER: "%s",
      PATH_PREFIX: "%s",
      INSTALL_CERT: true
    };
  `, conf.URL, conf.PathPrefix))

	r := ioutil.NewMultiReadSeeker(jsConf, f)

	http.ServeContent(res, req, file, fi.ModTime(), r)
}
Example #2
0
func (api *httpAPI) ServeApplicationJS(w http.ResponseWriter, req *http.Request, params httprouter.Params) {
	path := filepath.Join("app", "build", params.ByName("assetPath"))
	data, err := api.Asset(path)
	if err != nil {
		fmt.Println(err)
		w.WriteHeader(500)
		return
	}

	var jsConf bytes.Buffer
	jsConf.Write([]byte("window.InstallerConfig = "))
	json.NewEncoder(&jsConf).Encode(installerJSConfig{
		Endpoints: map[string]string{
			"install": "/install",
			"events":  "/events/:id",
			"prompt":  "/prompt/:id",
		},
		HasAWSEnvCredentials: api.AWSEnvCreds != nil,
	})
	jsConf.Write([]byte(";\n"))

	r := ioutil.NewMultiReadSeeker(bytes.NewReader(jsConf.Bytes()), data)

	http.ServeContent(w, req, path, time.Now(), r)
}
Example #3
0
func (api *httpAPI) ServeApplicationJS(w http.ResponseWriter, req *http.Request, params httprouter.Params) {
	path := filepath.Join("app", "build", params.ByName("assetPath"))
	data, err := api.Asset(path)
	if err != nil {
		httphelper.Error(w, err)
		api.logger.Debug(err.Error())
		return
	}

	var jsConf bytes.Buffer
	jsConf.Write([]byte("window.InstallerConfig = "))
	json.NewEncoder(&jsConf).Encode(api.clientConfig)
	jsConf.Write([]byte(";\n"))

	r := ioutil.NewMultiReadSeeker(bytes.NewReader(jsConf.Bytes()), data)

	http.ServeContent(w, req, path, time.Now(), r)
}
Example #4
0
File: api.go Project: kuntenz/flynn
func serveDashboardJs(res http.ResponseWriter, req *http.Request, conf *Config) {
	path := filepath.Join("app", "build", "assets", filepath.Base(req.URL.Path))
	data, t, err := AssetReader(path)
	if err != nil {
		fmt.Println(err)
		res.WriteHeader(500)
		return
	}

	var jsConf bytes.Buffer
	jsConf.Write([]byte("window.DashboardConfig = "))
	json.NewEncoder(&jsConf).Encode(DashboardConfig{
		AppName:     conf.AppName,
		ApiServer:   conf.URL,
		PathPrefix:  conf.PathPrefix,
		InstallCert: len(conf.CACert) > 0,
	})
	jsConf.Write([]byte(";\n"))

	r := ioutil.NewMultiReadSeeker(bytes.NewReader(jsConf.Bytes()), data)

	http.ServeContent(res, req, path, t, r)
}
Example #5
0
func (api *API) ServeDashboardJs(ctx context.Context, w http.ResponseWriter, req *http.Request) {
	log, _ := ctxhelper.LoggerFromContext(ctx)
	path := filepath.Join("app", "build", "assets", filepath.Base(req.URL.Path))
	data, t, err := AssetReader(path)
	if err != nil {
		log.Error(err.Error())
		httphelper.Error(w, err)
		return
	}

	var jsConf bytes.Buffer
	jsConf.Write([]byte("window.DashboardConfig = "))
	json.NewEncoder(&jsConf).Encode(DashboardConfig{
		AppName:     api.conf.AppName,
		ApiServer:   api.conf.URL,
		PathPrefix:  api.conf.PathPrefix,
		InstallCert: len(api.conf.CACert) > 0,
	})
	jsConf.Write([]byte(";\n"))

	r := ioutil.NewMultiReadSeeker(bytes.NewReader(jsConf.Bytes()), data)

	http.ServeContent(w, req, path, t, r)
}