-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
57 lines (50 loc) · 1.73 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
55
56
57
import { fileURLToPath } from "url";
import bodyParser from "body-parser";
import multer from "multer";
import * as dotenv from "dotenv";
dotenv.config();
import path from "path";
import express from "express";
import cors from "cors";
const app = express();
const PORT = 9000;
const __dirname = path.dirname(fileURLToPath(import.meta.url));
import { answerQnA } from "./controllers/queryQnA.js";
import { answerGenerative } from "./controllers/queryGenerative.js";
// import { answer } from "./controllers/makeChain.js";
// import { respond1 } from "./controllers/queryChain.js";
import { deleteNamespace } from "./controllers/deleteNamespace.js";
import { uploadFiles } from "./controllers/uploadFiles.js";
import apiRoutes from "./routes/api.js";
import authRoutes from "./routes/auth.js";
import mongoose from "mongoose";
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, "./docs");
},
filename: function (req, file, cb) {
cb(null, file.originalname);
},
});
const upload = multer({ storage: storage });
app.post("/upload", upload.array("files"), uploadFiles);
app.use("/api", apiRoutes);
app.use("/auth", authRoutes);
app.use("/docs", express.static(path.join(__dirname, "uploadedDocs")));
app.get("/delete", deleteNamespace);
// app.post("/query", answer);
// app.post("/query", respond1);
app.post("/queryQnA", answerQnA);
app.post("/queryGenerative", answerGenerative);
mongoose.set("strictQuery", false);
mongoose
.connect(process.env.MONGODB_URI)
.then((result) => {
app.listen(PORT, () => {
console.log(`App is listening on port ${PORT}...`);
});
})
.catch((err) => console.log(err));