-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
56 lines (44 loc) · 1.26 KB
/
server.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
54
55
56
const express = require('express');
const bodyParser = require('body-parser');
const passport = require('passport');
const cors = require('cors');
const fileupload = require('express-fileupload');
const path = require('path');
//configuring the env for the application
require('dotenv').config();
// Connect function helps to connect to the mongoDB
const connect = require('./config/db');
const router = require('./routes');
require('./services/cloudinary');
require('./config/passport')(passport);
const app = express();
connect();
app.use(cors());
// Using bodyparser middleware
app.use(
bodyParser.urlencoded({
extended: false,
})
);
app.use(bodyParser.json());
//letting the application to upload the image file and giving temporary directory as tmp.
app.use(
fileupload({
useTempFiles: true,
tempFileDir: '/tmp/',
})
);
app.use(passport.initialize());
app.use('/', router);
// Assume 404 since no routes and middlewares responded
app.use((req, res, next) => {
console.log('error (404)');
res.json({ Error: 404 });
});
if (process.env.NODE_ENV === 'development') {
app.use(express.static('frontend/build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'frontend', 'build', 'index.html'));
});
}
module.exports = app;