-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
27 lines (22 loc) · 847 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
const express = require('express');
const processInput = require('./process');
module.exports = async function startServer(manager) {
const app = express();
app.use(express.json());
app.post('/api/message', async (req, res) => {
const { language, text } = req.body;
if (!language || !text) {
return res.status(400).json({ error: 'Please provide both language and text in the request body.' });
}
try {
const answer = await processInput(manager, language, text);
res.json({ answer });
} catch (error) {
res.status(500).json({ error: 'An error occurred while processing the request.' });
}
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
};