Spaces:
Sleeping
Sleeping
Update app/server.js
Browse files- app/server.js +13 -2
app/server.js
CHANGED
|
@@ -45,7 +45,6 @@
|
|
| 45 |
// module.exports = router;
|
| 46 |
const express = require('express');
|
| 47 |
const multer = require('multer');
|
| 48 |
-
const cors = require('cors');
|
| 49 |
const {
|
| 50 |
addTask,
|
| 51 |
getTaskStatus,
|
|
@@ -60,7 +59,19 @@ const upload = multer();
|
|
| 60 |
// Debug: Server initialization
|
| 61 |
console.log('🔹 Initializing Shadow Backend...');
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
// ---------------- Submit new shadow task ----------------
|
| 66 |
router.post('/add-shadow', upload.single('file'), async (req, res) => {
|
|
|
|
| 45 |
// module.exports = router;
|
| 46 |
const express = require('express');
|
| 47 |
const multer = require('multer');
|
|
|
|
| 48 |
const {
|
| 49 |
addTask,
|
| 50 |
getTaskStatus,
|
|
|
|
| 59 |
// Debug: Server initialization
|
| 60 |
console.log('🔹 Initializing Shadow Backend...');
|
| 61 |
|
| 62 |
+
// ---------------- CORS Middleware ----------------
|
| 63 |
+
app.use((req, res, next) => {
|
| 64 |
+
res.setHeader('Access-Control-Allow-Origin', '*'); // Allow all origins
|
| 65 |
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
| 66 |
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
| 67 |
+
|
| 68 |
+
// Handle preflight requests
|
| 69 |
+
if (req.method === 'OPTIONS') {
|
| 70 |
+
return res.sendStatus(200);
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
next();
|
| 74 |
+
});
|
| 75 |
|
| 76 |
// ---------------- Submit new shadow task ----------------
|
| 77 |
router.post('/add-shadow', upload.single('file'), async (req, res) => {
|