-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
53 lines (40 loc) · 1.41 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
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
const mongoose = require('mongoose');
const fileUpload = require('express-fileupload')
// .env file configiration
require('dotenv').config();
const { mailTransport } = require('./utils/sendMail')
const bookRouter = require('./routes/book.route');
const authorRouter = require('./routes/author.route');
const userRouter = require('./routes/user.route');
var app = express();
app.use(fileUpload({
createParentPath: true
}))
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
// Connect with mongo data base
mongoose.connect(process.env.MONGO_URL)
.then(() => console.log('Data base connected successfully'))
.catch((err) => console.log('Error ', err.message));
// Use routes
app.use('/api/book', bookRouter);
app.use('/api/author', authorRouter);
app.use('/api/user', userRouter);
// use the upload folder to get images
app.use('/uploads', express.static(
path.join(__dirname, '/uploads')
))
if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(__dirname, '/client/build')))
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '/client/build', 'index.html'))
})
}
module.exports = app;