From 5bf13801592b86c3d4d71910bc96eab0d8e38931 Mon Sep 17 00:00:00 2001 From: Sean Park-Ross Date: Mon, 3 Feb 2025 16:39:16 +0000 Subject: [PATCH] Pre-emptive client side partial fix for cors error on data.pro.hasura.io --- src/theme/DocRoot/Layout/FetchUser/index.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/theme/DocRoot/Layout/FetchUser/index.js b/src/theme/DocRoot/Layout/FetchUser/index.js index f85baf35e..8e47af996 100644 --- a/src/theme/DocRoot/Layout/FetchUser/index.js +++ b/src/theme/DocRoot/Layout/FetchUser/index.js @@ -2,14 +2,14 @@ export default async function fetchUser() { const url = 'https://data.pro.hasura.io/v1/graphql'; const headers = { - Accept: '*/*', + 'Accept': '*/*', 'Accept-Language': 'en-US,en;q=0.9,es-US;q=0.8,es;q=0.7', 'Content-Type': 'application/json', 'Hasura-Client-Name': 'hasura-docs', - Origin: 'https://hasura.io/docs/3.0', - Referer: 'https://hasura.io/docs/3.0', - 'Sec-Fetch-Mode': 'cors', - 'Sec-Fetch-Site': 'same-site', + 'Origin': 'https://hasura.io', + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'POST, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type', }; const body = { @@ -27,9 +27,15 @@ export default async function fetchUser() { const response = await fetch(url, { method: 'POST', headers: headers, + credentials: 'include', + mode: 'cors', body: JSON.stringify(body), }); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const data = await response.json(); console.log(data); return data;