-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
56 lines (39 loc) · 1.27 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
require('dotenv').config({path: "./config.env"})
const express= require('express')
const app = express()
const bodyParser=require('body-parser');
const connectDB = require('./config/db')
const morgan = require("morgan");
const cors = require("cors");
const path = require("path")
app.use(express.static(path.join(__dirname, 'client/build')));
connectDB()
// app.use(express.json())
const talkToChatbot = require("./chatbot");
app.use(bodyParser.json({limit:'50mb'}));
app.use(bodyParser.urlencoded({limit:'50mb', extended:true}));
app.use(cors());
app.use(morgan("dev"));
app.use('/api/auth',require('./routes/auth'))
app.use('/api/private',require('./routes/private'))
app.post("/chatbot", function (req, res, next) {
const message = req.body.message;
console.log("message" + message);
talkToChatbot(message)
.then((response) => {
res.send({ message: response });
})
.catch((error) => {
console.log("Something went wrong: " + error);
res.send({
error: "Error occured here"
});
});
});
const PORT = process.env.PORT||5000;
app.get('*', (req,res) =>{
res.sendFile(path.join(__dirname+'/client/build/index.html'));
});
app.listen(PORT,()=>{
console.log(`Server is running on port ${PORT}`)
})