-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
40 lines (32 loc) · 1014 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import express from "express";
import cors from "cors";
import dotenv from "dotenv";
import multer from "multer"; // Import multer
import chat from "./chat.js";
dotenv.config();
const app = express();
app.use(cors());
// Configure multer
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, "uploads/");
},
filename: function (req, file, cb) {
cb(null, file.originalname);
},
});
const upload = multer({ storage: storage });
const PORT = process.env.PORT || 5001;
let filePath;
app.post("/upload", upload.single("file"), async (req, res) => {
// Use multer to handle file upload
filePath = req.file.path; // The path where the file is temporarily saved
res.send(filePath + " upload successfully.");
});
app.get("/chat", async (req, res) => {
const resp = await chat(filePath, req.query.question); // Pass the file path to your main function
res.send(resp.text);
});
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});