-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
44 lines (40 loc) · 1.12 KB
/
server.js
File metadata and controls
44 lines (40 loc) · 1.12 KB
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
import express from "express";
import cors from "cors";
import path from "path";
import { config } from "dotenv";
config();
import { gptres } from "./chatGptRes.js";
import { textToSpeechfunc } from "./textToSpeech.js";
import { fileURLToPath } from "url";
import { dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const app = express();
const port = process.env.PORT || 3000;
app.use(
express.static(path.join(__dirname, "public"), {
setHeaders: (res) => {
res.setHeader("Cache-Control", "no-cache");
},
}),
);
app.use(express.text());
app.use(cors());
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "public", "index.html"));
});
app.post("/demo", (req, res) => {
console.log("request reached server..!");
res.send("hello...");
});
app.post("/gpttext", async (req, res) => {
const text = req.body;
console.log(text);
const gptTextResponse = await gptres(text);
const id = await textToSpeechfunc(gptTextResponse);
console.log(id);
res.status(200).send(id);
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});