fix(client): 🐛 disable cors in case client is served from another domain
This commit is contained in:
parent
65024b444e
commit
5819c6174c
|
@ -14,7 +14,9 @@
|
||||||
export async function sendCommand(command, value) {
|
export async function sendCommand(command, value) {
|
||||||
const endpoint = getEndpoint()
|
const endpoint = getEndpoint()
|
||||||
const url = new URL(`/get?command=${command}&value=${value}`, endpoint)
|
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()
|
const text = await response.text()
|
||||||
console.log(text)
|
console.log(text)
|
||||||
}
|
}
|
||||||
|
@ -54,7 +56,10 @@ export function setEndpoint(endpoint) {
|
||||||
*/
|
*/
|
||||||
export async function testEndpoint(endpoint) {
|
export async function testEndpoint(endpoint) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(endpoint)
|
const url = new URL('/get', endpoint)
|
||||||
|
const response = await fetch(url, {
|
||||||
|
mode: 'no-cors'
|
||||||
|
})
|
||||||
if (response.ok) return
|
if (response.ok) return
|
||||||
} catch (cause) {
|
} catch (cause) {
|
||||||
alert(`Impossible de joindre l'adresse "${endpoint}"`)
|
alert(`Impossible de joindre l'adresse "${endpoint}"`)
|
||||||
|
|
Loading…
Reference in a new issue