-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (31 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
require('dotenv').config()
const express = require('express')
const mongoose = require('mongoose')
const cors = require('cors')
const userRoutes = require('./controllers/users')
const departmentRoutes = require('./controllers/departments')
const employeesRoutes = require('./controllers/employees')
const app = express()
app.use(cors())
app.use(`/content`, express.static(`content/`))
app.use(express.static(__dirname + `/client/build`))
app.use(express.json())
app.use('/api/users', userRoutes)
app.use('/api/departments', departmentRoutes)
app.use('/api/employees', employeesRoutes)
mongoose
.connect(process.env.MONGODB_CONNECTION_URL)
.then(() => {
console.log('database connected successfully!!')
})
.catch((error) => {
console.log(error)
})
app.all("*", (req, res) => {
res.sendFile(__dirname + `/client/build/index.html`)
})
app.use((err, req, res, next) => {
if (err) res.status(400).json({ error: err.message })
else next()
})
app.listen(process.env.PORT || 5000, () => console.log(`server is listening at port 5000 `))