-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (22 loc) · 810 Bytes
/
server.js
File metadata and controls
27 lines (22 loc) · 810 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
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors') // Add this line
const { JoiWithCyberbullying } = require('./lib') // Update with actual path
const app = express();
const PORT = process.env.PORT || 5001
app.use(cors()); // Add this line to enable CORS for all routes
app.use(bodyParser.json())
// API endpoint for detecting cyberbullying
app.post('/api/detect-cyberbullying', async (req, res) => {
const { message } = req.body
const schema = JoiWithCyberbullying.string().cyberbullying()
try {
const result = await schema.validateAsync(message)
res.json({ response: result })
} catch (error) {
res.status(400).json({ error: error.message })
}
})
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`)
})