-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
hook.server.ts does not work for a preflight request #8963
Comments
Can you tell what response is being returned by the preflight response, if not a successful response? Do you need to return |
@Conduitry The error message is below.
Yes need to return to the allowed origin url. |
I added hooks.server.ts import type { Handle } from '@sveltejs/kit';
export const handle: Handle = async ({ event, resolve }) => {
const response = await resolve(event);
if (event.url.pathname.includes('/api')) {
// https://chat.openai.com
response.headers.set('Access-Control-Allow-Origin', 'https://example.com');
response.headers.set('Access-Control-Allow-Methods', 'GET,OPTIONS,POST');
response.headers.set('Access-Control-Allow-Headers', '*');
response.headers.set('Access-Control-Max-Age', '86400');
}
return response;
}; |
The problem was #5193 (comment) |
Look #5193 (comment) to solve the issue. |
Describe the bug
Error message on client side:
Access to fetch at 'https://myapp-vercel.app/api/search' from origin 'https://chat.openai.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
Reproduction
hooks.server.ts (Deployed to Vercel.)
+server.ts (Deployed to Vercel.)
Fetching from the origin (https://example.com) on client side:
Logs
System Info
Severity
annoyance
Additional Information
No response
The text was updated successfully, but these errors were encountered: