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)}}`
|
||||
{{end}}
|
||||
}
|
||||
{{range $key, $value := .Data.headers}}
|
||||
request.setRequestHeader("{{$key}}", "{{$value}}")
|
||||
{{end}}
|
||||
request.send()
|
||||
</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>
|
||||
</div>
|
||||
<script>
|
||||
var request = new XMLHttpRequest()
|
||||
request.open('GET', "{{proxy (printf `https://www.metaweather.com/api/location/%s/` .Data.woeid)}}", true)
|
||||
var wtrRequest = new XMLHttpRequest()
|
||||
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)}
|
||||
request.onload = function () {
|
||||
wtrRequest.onload = function () {
|
||||
const data = JSON.parse(this.response)
|
||||
document.getElementById('weatherLoading_{{$randID}}').classList.add("is-hidden")
|
||||
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('weatherPredictabilityText_{{$randID}}').innerText = "Predictability: " + data["consolidated_weather"][0]["predictability"] + "%"
|
||||
}
|
||||
request.send()
|
||||
wtrRequest.setRequestHeader("Content-Type", "text/plain")
|
||||
wtrRequest.send()
|
||||
</script>
|
||||
|
19
routes.go
19
routes.go
@ -205,6 +205,7 @@ func registerRoutes(app App) {
|
||||
}
|
||||
// Create new HTTP client with 5 second timeout
|
||||
client := http.Client{Timeout: 5 * time.Second}
|
||||
proxyReq.Header = req.Header
|
||||
// Use client to do request created above
|
||||
proxyRes, err := client.Do(proxyReq)
|
||||
if err != nil {
|
||||
@ -214,6 +215,24 @@ func registerRoutes(app App) {
|
||||
}
|
||||
// Close proxy response body at end of function
|
||||
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
|
||||
io.Copy(res, proxyRes.Body)
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user