mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-19 21:18:25 +02:00
Add alternative POST method for deleting advertisements to bypass restrictions
Implement a POST endpoint on the API and a fallback POST request in the frontend for deleting advertisements, addressing issues where the DELETE method might be blocked in production environments. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 1e4433b5-47ab-464c-b663-fea2e53367dd Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/1e4433b5-47ab-464c-b663-fea2e53367dd/qwRLDDO
This commit is contained in:
1 parent
9ad2afaf90
commit
8f51b30776
5 files changed
+274
-14
No files matched your search
@@ -94,16 +94,42 @@ export default function Publicities() {
|
||||
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: async (id: number) => {
|
||||
const response = await fetch(`/api/publicities/${id}`, { method: 'DELETE' });
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
throw new Error(error.message || 'Erreur lors de la suppression');
|
||||
// Try POST first (for production environments that block DELETE)
|
||||
console.log(`🗑️ [Frontend] Attempting to delete publicity ${id} using POST method`);
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/publicities/${id}/delete`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({})
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
console.log(`✅ [Frontend] Successfully deleted publicity ${id} using POST`);
|
||||
return response.json();
|
||||
} else if (response.status === 404) {
|
||||
// Route not found, try DELETE method as fallback (for dev environment)
|
||||
console.log(`⚠️ [Frontend] POST route not found, trying DELETE method`);
|
||||
const deleteResponse = await fetch(`/api/publicities/${id}`, { method: 'DELETE' });
|
||||
|
||||
if (!deleteResponse.ok) {
|
||||
const error = await deleteResponse.json();
|
||||
throw new Error(error.message || 'Erreur lors de la suppression');
|
||||
}
|
||||
|
||||
// Handle empty response (204 No Content)
|
||||
if (deleteResponse.status === 204) {
|
||||
return { message: "Publicity deleted successfully" };
|
||||
}
|
||||
return deleteResponse.json();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
throw new Error(error.message || 'Erreur lors de la suppression');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`❌ [Frontend] Failed to delete publicity ${id}:`, error);
|
||||
throw error;
|
||||
}
|
||||
// Handle empty response (204 No Content) in production
|
||||
if (response.status === 204) {
|
||||
return { message: "Publicity deleted successfully" };
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['/api/publicities'] });
|
||||
|
||||
Reference in new issue
Block a user