-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
42 lines (36 loc) · 1.05 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
const express = require('express')
const { config } = require('dotenv')
const bodyparser = require('body-parser')
const AppError = require('./utils/appError')
const cors = require('cors')
config()
require('./db')
const path = require('path')
const userRoutes = require('./routes/userRoutes')
const errorHandler = require('./handler/errorHandler')
const app = express()
// app.use(cookieParser());
app.use(bodyparser.json())
app.use(express.json())
app.use(
cors()
// cors({
// origin: "http://localhost:3001",
// credentials: true,
// allowedHeaders: ["Content-Type"]
// })
)
app.options('*', cors())
app.use(userRoutes)
app.all( '*', (req, _, next) => {
next(new AppError(`can not find route ${req.originalUrl} in this server`, 404))
})
app.use(errorHandler)
// for heroku deployement
if(process.env.NODE_ENV === 'production'){
app.use(express.static(path.resolve(__dirname, 'client', 'build')));
app.get('*', (req, res)=>{
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
module.exports = app