-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (31 loc) · 1.01 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
38
39
40
const express = require('express')
const cors = require('cors')
const cookieParser = require('cookie-parser')
const mongoose = require("mongoose")
const authRoutes = require('./routes/auth')
const userRoutes = require('./routes/user')
const { initSocket } = require('./socket/index')
const app = express()
require('dotenv').config()
const corsOptions = {
origin: process.env.CLIENT_URL,
credentials: true
};
app.use(cors(corsOptions))
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(cookieParser(process.env.COOKIE_SIGNATURE))
app.use('/api/auth', authRoutes)
app.use('/api/users', userRoutes)
app.get('/', (req, res) => {
res.send('Hi there!')
})
mongoose.connect(process.env.MONGO_URI)
.then(() => console.log("DB connection Success"))
.catch((err) => console.log('DB connection Error', err.message))
const server = app.listen(process.env.PORT, () => {
console.log(`App is listening to port ${process.env.PORT}`)
})
// socket.io
initSocket(server, corsOptions)
module.exports = app;