-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (33 loc) · 1.03 KB
/
index.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
const express = require('express')
const cors = require('cors')
const { default: mongoose } = require('mongoose')
const dotenv = require('dotenv')
const app = express()
dotenv.config()
const corsOptions = {
origin: 'http://localhost:5173', // Replace with your client's origin
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
credentials: true,
optionsSuccessStatus: 204
};
app.use(express.json())
app.use(cors(corsOptions));
const userRoute = require("./routes/userRoute")
const chatRoute = require("./routes/chatRoute")
const messageRoute = require("./routes/messageRoute")
app.use("/api/users", userRoute)
app.use("/api/chats", chatRoute)
app.use("/api/messages", messageRoute
)
const PORT = process.env.PORT || 5000
mongoose.connect(process.env.ATLAS_URI).then(()=>{
console.log('Connected to MongoDB')
}).catch((error)=>{
console.error('Error connecting to MongoDB:', error)
})
app.get('/', (req, res) => {
res.send('Welcome to AI ChatBox API')
})
app.listen(PORT, ((req, res)=>{
console.log(`listening on ${PORT}`)
}))