From 0aa8a3842cadc2f64a777f47cb129da6f16d89f5 Mon Sep 17 00:00:00 2001 From: Kshitij Date: Sat, 21 Jun 2025 00:22:49 +0530 Subject: [PATCH] Merged models/ directory from bhakti's branch up to commit 3d79d696409df063f3eae69ffddcbdc74de616fb since that is the branch we used for demo during hackathon. --- models/server.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/models/server.js b/models/server.js index 7649954..c82087c 100644 --- a/models/server.js +++ b/models/server.js @@ -3,10 +3,19 @@ const express = require("express"); const { spawn } = require("child_process"); const path = require("path"); const upload = require("./Middleware/multer"); +const cors = require("cors"); const app = express(); const PORT = 3000; +const corsOptions = { + origin: "http://localhost:5173", + methods: "GET,HEAD,PUT,PATCH,POST,DELETE", + credentials: true, +}; + +app.use(cors(corsOptions)); + // Endpoint to run the Python script app.post("/predict", upload.single("image"), (req, res) => { console.log("File is uploaded successfully" + req.file?.path); @@ -22,7 +31,13 @@ app.post("/predict", upload.single("image"), (req, res) => { // Collect data from the script pythonProcess.stdout.on("data", (data) => { console.log(`Output: ${data}`); - res.send(data.toString()); // Send the output back to the client + + res.status(200).json({ + success: true, + message: "Image uploaded successfully", + data: data.toString(), + }); + //res.send(data.toString()); // Send the output back to the client }); // Handle errors