qwik
qwik copied to clipboard
Cors bug when using Link
Qwik Version
0.12.1
Operating System (or Browser)
Any
Node Version (if applicable)
No response
Which component is affected?
Qwik City
Expected Behaviour
useResource is able to handle cors exactly the same when directly accessing a page or from a Link
Actual Behaviour
On access a page following a Link
the useResource
shows a cors problem
Additional Information
This is strange because on access directly a page the fetch request is working perfect but when the same function is executed as a result of a page visit from a Link
is not working
const reposResource = useResource$<string[]>(({ track }) => {
track(() => user.auth)
return getRepositories(user.auth)
})
export async function getRepositories(token: string): Promise<string[]> {
const response = await fetch(`http://localhost:3000/repositories`, {
headers: {
Authorization: 'Bearer whatever,
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
},
})
.then((res) => res.json())
.catch((err) => console.log(err))
return response
}
This always give an error from Link
The most interesting part is if I ignore the error and just return response without catch
data is correctly appearing on the app but I st get the cors issue on the console.