allow setting no-cors in ping service

Signed-off-by: Jayadeep KM <kmjayadeep@gmail.com>
This commit is contained in:
Jayadeep KM 2023-05-22 07:06:07 +02:00
parent df903a2c04
commit 37509200fc
No known key found for this signature in database
GPG Key ID: E144EC9E6313D549
3 changed files with 10 additions and 1 deletions

View File

@ -144,6 +144,8 @@ For Ping you need to set the type to Ping and provide a url. By default the HEAD
method: "head"
```
You can also specify an optional field `mode` as `no-cors` to allow cross-origin requests from the browser. Setting this field will show the status of the service as `online` if the request is successful, irrespective of the response status code. Check the official [documentation](https://developer.mozilla.org/en-US/docs/Web/API/Request/mode) for more information about this field.
## Prometheus
For Prometheus you need to set the type to Prometheus and provide a url.

View File

@ -39,7 +39,9 @@ export default {
return;
}
this.fetch("/", { method, cache: "no-cache" }, false)
const mode = typeof this.item.mode === "string" ? this.item.mode : "cors";
this.fetch("/", { method, cache: "no-cache", mode }, false)
.then(() => {
this.status = "online";
})

View File

@ -38,6 +38,11 @@ export default {
}
return fetch(url, options).then((response) => {
if (response.type == "opaque") {
// For no-cors requests, return empty response
return ""
}
if (!response.ok) {
throw new Error("Not 2xx response");
}