support CORS preflight requests

This commit is contained in:
2026-09-06 17:59:28 +03:00
parent 61dd409997
commit 1d6bb71478
+10
View File
@@ -715,6 +715,16 @@ const aiJobRunner = startAiJobRunner(async (job,{signal}) => {
const server = http.createServer(async (req, res) => { const server = http.createServer(async (req, res) => {
const url = new URL(req.url, `http://localhost:${PORT}`); const url = new URL(req.url, `http://localhost:${PORT}`);
if (req.method === 'OPTIONS') {
res.writeHead(204, {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,POST,PUT,PATCH,DELETE,OPTIONS',
'Access-Control-Allow-Headers': 'Authorization,Content-Type',
'Access-Control-Max-Age': '600',
});
res.end();
return;
}
try { try {
if (url.pathname === '/api/me/ai-jobs') { if (url.pathname === '/api/me/ai-jobs') {
const user=userFromAuthHeader(req.headers.authorization); const user=userFromAuthHeader(req.headers.authorization);