fix(client): 🐛 disable cors in case client is served from another domain

This commit is contained in:
Julien Oculi 2024-06-26 12:14:30 +02:00
parent 65024b444e
commit 5819c6174c

View file

@ -14,7 +14,9 @@
export async function sendCommand(command, value) {
const endpoint = getEndpoint()
const url = new URL(`/get?command=${command}&value=${value}`, endpoint)
const response = await fetch(url)
const response = await fetch(url, {
mode: 'no-cors'
})
const text = await response.text()
console.log(text)
}
@ -54,7 +56,10 @@ export function setEndpoint(endpoint) {
*/
export async function testEndpoint(endpoint) {
try {
const response = await fetch(endpoint)
const url = new URL('/get', endpoint)
const response = await fetch(url, {
mode: 'no-cors'
})
if (response.ok) return
} catch (cause) {
alert(`Impossible de joindre l'adresse "${endpoint}"`)