fixed cors headers

This commit is contained in:
Jonas_Jones 2024-06-22 01:29:03 +02:00
parent af9eccb50d
commit 4577983233

View file

@ -104,26 +104,26 @@ const headersCORS = {
}); });
// If the put operation succeeds (no error is thrown), return a success response // If the put operation succeeds (no error is thrown), return a success response
return new Response(`Post Successfully uploaded`, { status: 200 }); return new Response(`Post Successfully uploaded`, { status: 200, headers: headersCORS });
} catch (error) { } catch (error) {
// If an error occurs during the put operation, return a failure response // If an error occurs during the put operation, return a failure response
return new Response(`Failed to upload Post: ${error.message}`, { status: 500 }); return new Response(`Failed to upload Post: ${error.message}`, { status: 500, headers: headersCORS });
} }
} catch (e) { } catch (e) {
return new Response(e, { status: 400 }); return new Response(e, { status: 400, headers: headersCORS });
} }
} else { } else {
return new Response('Method Not Allowed', { status: 405 }); return new Response('Method Not Allowed', { status: 405, headers: headersCORS });
} }
} else if (url.pathname === "/blog/delete_post") { } else if (url.pathname === "/blog/delete_post") {
if (request.method === 'DELETE') { if (request.method === 'DELETE') {
if (!hasValidHeader(request)) { if (!hasValidHeader(request)) {
return new Response('Unauthorized', { status: 401 }); return new Response('Unauthorized', { status: 401, headers: headersCORS });
} }
try { try {
@ -158,15 +158,15 @@ const headersCORS = {
} }
}); });
return new Response(`Post Successfully deleted`, { status: 200 }); return new Response(`Post Successfully deleted`, { status: 200, headers: headersCORS });
} catch (e) { } catch (e) {
return new Response('Failed to delete Post', { status: 500 }); return new Response('Failed to delete Post: ' + e, { status: 500, headers: headersCORS });
} }
} }
return new Response('Method Not Allowed', { status: 405 }); return new Response('Method Not Allowed', { status: 405, headers: headersCORS });
} else { } else {
// Handle other routes or return a 404 response // Handle other routes or return a 404 response
return new Response('Not Found', { status: 404 }); return new Response('Not Found', { status: 404, headers: headersCORS });
} }
}; };
@ -190,9 +190,9 @@ const headersCORS = {
return `<?xml version="1.0" encoding="UTF-8" ?> return `<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0"> <rss version="2.0">
<channel> <channel>
<title>Your Blog Title</title> <title>Jonas_Jones Blog</title>
<link>${DOMAIN}</link> <link>${DOMAIN}</link>
<description>Your blog description</description> <description>Blog by Jonas_Jones</description>
<language>en-us</language> <language>en-us</language>
<pubDate>${new Date().toUTCString()}</pubDate> <pubDate>${new Date().toUTCString()}</pubDate>
<lastBuildDate>${new Date().toUTCString()}</lastBuildDate> <lastBuildDate>${new Date().toUTCString()}</lastBuildDate>