-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathserver.js
More file actions
51 lines (40 loc) · 1.1 KB
/
Copy pathserver.js
File metadata and controls
51 lines (40 loc) · 1.1 KB
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
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const config = require('./config/main');
const morgan = require('morgan');
const passport = require('passport');
app.use(
bodyParser.urlencoded({
extended: false
})
);
app.use(bodyParser.json());
// log requests to console
app.use(morgan('dev'));
// Initialize passport for user
app.use(passport.initialize());
// Database connection
mongoose.Promise = global.Promise;
mongoose.connect(
config.database,
function(error) {
if (error) {
console.log(error);
} else {
console.log('Database connected successfully');
}
}
);
// Bringing passport strategy
require('./config/passport')(passport);
const api = require('./api');
app.use('/api', api);
const path = require('path');
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 || 5000;
app.listen(PORT, () => console.log(`Server is running on port ${PORT}`));