webbundle: give preference to generated config.js

This commit is contained in:
Simone Gotti 2019-05-16 10:05:32 +02:00
parent 30f398e361
commit c02ed89d6e

View File

@ -32,7 +32,6 @@ const configTplText = `
const CONFIG = { const CONFIG = {
API_URL: '{{.ApiURL}}', API_URL: '{{.ApiURL}}',
API_BASE_PATH: '{{.ApiBasePath}}', API_BASE_PATH: '{{.ApiBasePath}}',
authType: '{{.AuthType}}'
} }
window.CONFIG = CONFIG window.CONFIG = CONFIG
@ -48,11 +47,9 @@ func NewWebBundleHandlerFunc(gatewayURL string) func(w http.ResponseWriter, r *h
configTplData := struct { configTplData := struct {
ApiURL string ApiURL string
ApiBasePath string ApiBasePath string
AuthType string
}{ }{
gatewayURL, gatewayURL,
"/api/v1alpha", "/api/v1alpha",
"local",
} }
configTpl.Execute(&buf, configTplData) configTpl.Execute(&buf, configTplData)
@ -66,11 +63,7 @@ func NewWebBundleHandlerFunc(gatewayURL string) func(w http.ResponseWriter, r *h
AssetDir: webbundle.AssetDir, AssetDir: webbundle.AssetDir,
AssetInfo: webbundle.AssetInfo, AssetInfo: webbundle.AssetInfo,
}) })
// check if the required file is available in the webapp asset and serve it
if _, err := webbundle.Asset(r.URL.Path[1:]); err == nil {
fileServerHandler.ServeHTTP(w, r)
return
}
// config.js is the external webapp config file not provided by the // config.js is the external webapp config file not provided by the
// asset and not needed when served from the api server // asset and not needed when served from the api server
if r.URL.Path == "/config.js" { if r.URL.Path == "/config.js" {
@ -81,6 +74,12 @@ func NewWebBundleHandlerFunc(gatewayURL string) func(w http.ResponseWriter, r *h
return return
} }
// check if the required file is available in the webapp asset and serve it
if _, err := webbundle.Asset(r.URL.Path[1:]); err == nil {
fileServerHandler.ServeHTTP(w, r)
return
}
// skip /api requests // skip /api requests
if strings.HasPrefix(r.URL.Path, "/api/") { if strings.HasPrefix(r.URL.Path, "/api/") {
http.Error(w, "", http.StatusNotFound) http.Error(w, "", http.StatusNotFound)