-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
34 lines (28 loc) · 1004 Bytes
/
Copy pathserver.js
File metadata and controls
34 lines (28 loc) · 1004 Bytes
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
const express = require('express');
const cors = require('cors');
const OpenAiApi = require('./OpenAiApi.js');
require('dotenv').config();
const app = express();
const port = 3000;
// Setup OpenAiApi with your API key
const openAiApi = new OpenAiApi(process.env.API_KEY);
app.use(cors()); // Enable CORS for all routes
app.use(express.json());
// Serve static files from the 'public' directory
app.use(express.static('public'));
app.post('/generateWords', async (req, res) => {
try {
const userName = req.body.userName || '';
//const prevInput = req.body.prevInput || '';
console.log("do we get to server.js")
console.log(userName)
const response = await openAiApi.generateWords(userName);
console.log("but we never get here")
res.json({ words: response });
} catch (error) {
res.status(500).send('Error generating words');
}
});
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});