Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting no-cors in ping service #651

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/customservices.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion src/components/services/Ping.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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";
})
Expand Down
5 changes: 5 additions & 0 deletions src/mixins/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down