-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
54 lines (42 loc) · 1.18 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import express from "express";
import cors from "cors";
import dotenv from "dotenv";
import multer from "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,
});
const PORT = 5001;
// const PORT = process.env.PORT || 8080; // github 部署
let filePath;
// RESTful - what does the API do? You should be able to describe it in one sentence.
// GET/POST/DELETE/PATCH/UDPATE
// ststua code 200, 401, 404, 500
// input paylod? param?
// output
app.get("/", (req, res) => {
res.send("healthy");
});
app.post("/upload", upload.single("file"), (req, res) => {
filePath = req.file.path;
res.send(filePath + " upload successfully.");
});
app.get("/chat", async (req, res) => {
const resp = await chat(req.query.question, filePath);
res.send(resp.text);
});
app.listen(PORT, () => {
console.log(`🚀🚀🚀 Server is running on port ${PORT}`);
});