Change variable name to prevent conflicts
This commit is contained in:
parent
062f329448
commit
61ed6e1872
4
.gitm.toml
Normal file
4
.gitm.toml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[repos]
|
||||||
|
origin = "ssh://git@192.168.100.62:2222/Arsen6331/simpledash.git"
|
||||||
|
gitlab = "git@gitlab.com:moussaelianarsen/simpledash.git"
|
||||||
|
github = "git@github.com:Arsen6331/simpledash.git"
|
@ -29,5 +29,8 @@
|
|||||||
document.getElementById("{{printf `APIElement%d_%s` $index $randID}}").innerHTML = `{{unescJS (trim $fmtStr)}}`
|
document.getElementById("{{printf `APIElement%d_%s` $index $randID}}").innerHTML = `{{unescJS (trim $fmtStr)}}`
|
||||||
{{end}}
|
{{end}}
|
||||||
}
|
}
|
||||||
|
{{range $key, $value := .Data.headers}}
|
||||||
|
request.setRequestHeader("{{$key}}", "{{$value}}")
|
||||||
|
{{end}}
|
||||||
request.send()
|
request.send()
|
||||||
</script>
|
</script>
|
@ -24,10 +24,10 @@
|
|||||||
<span class="card-footer-item">Data from <a href="https://www.metaweather.com" class="has-text-info">Metaweather</a></span>
|
<span class="card-footer-item">Data from <a href="https://www.metaweather.com" class="has-text-info">Metaweather</a></span>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
var request = new XMLHttpRequest()
|
var wtrRequest = new XMLHttpRequest()
|
||||||
request.open('GET', "{{proxy (printf `https://www.metaweather.com/api/location/%s/` .Data.woeid)}}", true)
|
wtrRequest.open('GET', "{{proxy (printf `https://www.metaweather.com/api/location/%s/` .Data.woeid)}}", true)
|
||||||
const round = function (flt){return Number.parseFloat(flt).toPrecision(3)}
|
const round = function (flt){return Number.parseFloat(flt).toPrecision(3)}
|
||||||
request.onload = function () {
|
wtrRequest.onload = function () {
|
||||||
const data = JSON.parse(this.response)
|
const data = JSON.parse(this.response)
|
||||||
document.getElementById('weatherLoading_{{$randID}}').classList.add("is-hidden")
|
document.getElementById('weatherLoading_{{$randID}}').classList.add("is-hidden")
|
||||||
document.getElementById('weatherStateText_{{$randID}}').innerText = data["consolidated_weather"][0]["weather_state_name"]
|
document.getElementById('weatherStateText_{{$randID}}').innerText = data["consolidated_weather"][0]["weather_state_name"]
|
||||||
@ -40,5 +40,6 @@
|
|||||||
document.getElementById('weatherVisibilityText_{{$randID}}').innerText = "Visibility: " + round(data["consolidated_weather"][0]["visibility"]) + "mi"
|
document.getElementById('weatherVisibilityText_{{$randID}}').innerText = "Visibility: " + round(data["consolidated_weather"][0]["visibility"]) + "mi"
|
||||||
document.getElementById('weatherPredictabilityText_{{$randID}}').innerText = "Predictability: " + data["consolidated_weather"][0]["predictability"] + "%"
|
document.getElementById('weatherPredictabilityText_{{$randID}}').innerText = "Predictability: " + data["consolidated_weather"][0]["predictability"] + "%"
|
||||||
}
|
}
|
||||||
request.send()
|
wtrRequest.setRequestHeader("Content-Type", "text/plain")
|
||||||
|
wtrRequest.send()
|
||||||
</script>
|
</script>
|
||||||
|
19
routes.go
19
routes.go
@ -205,6 +205,7 @@ func registerRoutes(app App) {
|
|||||||
}
|
}
|
||||||
// Create new HTTP client with 5 second timeout
|
// Create new HTTP client with 5 second timeout
|
||||||
client := http.Client{Timeout: 5 * time.Second}
|
client := http.Client{Timeout: 5 * time.Second}
|
||||||
|
proxyReq.Header = req.Header
|
||||||
// Use client to do request created above
|
// Use client to do request created above
|
||||||
proxyRes, err := client.Do(proxyReq)
|
proxyRes, err := client.Do(proxyReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -214,6 +215,24 @@ func registerRoutes(app App) {
|
|||||||
}
|
}
|
||||||
// Close proxy response body at end of function
|
// Close proxy response body at end of function
|
||||||
defer proxyRes.Body.Close()
|
defer proxyRes.Body.Close()
|
||||||
|
/*
|
||||||
|
var proxyReader io.Reader
|
||||||
|
switch proxyRes.Header.Get("Content-Type") {
|
||||||
|
case "application/x-gzip":
|
||||||
|
gzReader, err := gzip.NewReader(proxyRes.Body)
|
||||||
|
if err != nil {
|
||||||
|
httpError(res, app.Templates["error"], app.Config, http.StatusInternalServerError, "Decompressing response failed")
|
||||||
|
Log.Warn().Err(err).Msg("Error executing request for proxy")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
proxyReader = gzReader
|
||||||
|
} else {
|
||||||
|
proxyReader = proxyRes.Body
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
for key := range proxyRes.Header {
|
||||||
|
res.Header().Set(key, proxyRes.Header.Get(key))
|
||||||
|
}
|
||||||
// Copy data from proxy response to response
|
// Copy data from proxy response to response
|
||||||
io.Copy(res, proxyRes.Body)
|
io.Copy(res, proxyRes.Body)
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user