-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (38 loc) · 1.21 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
36
37
38
39
40
41
42
43
44
45
46
47
48
const http = require('http');
const path = require('path');
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const fileUpload = require('express-fileupload');
if (process.env.NODE_ENV !== 'production') require('dotenv').config();
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
});
mongoose.connection
.once('open', () => console.log('SUCCESS: Database Connection'))
.on('error', () => console.log('ERROR: Database Connection'));
const app = express();
app.use(cors());
app.use(fileUpload());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static('public'));
require('./models');
require('./passport-config');
require('./routes')(app);
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'));
});
}
const PORT = process.env.PORT || 3005;
http
.createServer(app)
.listen(PORT)
.on('listening', () => {
// console.clear();
console.log(`Server running on PORT ${PORT}`);
});