-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (42 loc) · 1.22 KB
/
app.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
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors')
const helmet = require('helmet')
const xss = require('xss-clean')
const path = require('path')
require('dotenv').config()
require('express-async-errors');
const jobRouter = require('./routes/jobRoute');
const authRouter = require('./routes/authRoute');
const errorHandler = require('./middleware/errorHandler')
const authMiddleWare = require('./middleware/authMiddleware')
const app = express();
app.use(cors())
app.use(helmet())
app.use(xss())
app.use(express.json());
app.use(express.static(path.resolve(__dirname, './client/build')))
app.use('/api/v1/auth', authRouter);
app.use('/api/v1/jobs', authMiddleWare, jobRouter);
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, './client/build', 'index.html'))
})
app.use(errorHandler)
const connectDB = async() => {
await mongoose.connect(process.env.MONGO_URL)
}
const PORT = process.env.PORT || 5000;
const start = async () => {
try {
await connectDB();
app.listen(PORT, () => {
console.log(`Server listening on PORT ${PORT}`)
})
} catch(err) {
console.log(err)
}
}
start();
module.exports = {
connectDB
}