support CORS preflight requests
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user