-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
45 lines (37 loc) · 1.42 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
const express = require('express');
const path = require('path');
const passport = require('passport');
const mongoose = require('mongoose');
const localSignup = require('./server/passport/local-signup');
const localLogin = require('./server/passport/local-login');
// @TODO: change locals vars en ENV
const config = require('./config');
const App = express();
mongoose.connect(config.db, {
useUnifiedTopology: true,
useNewUrlParser: true,
});
mongoose.Promise = global.Promise;
let db = mongoose.connection;
db.on('error', (err) => console.log(err));
db.once('open', () => console.log('connected to mongodb'));
App.use(express.json());
passport.use('local-signup', localSignup);
passport.use('local-login', localLogin);
const authRoutes = require('./server/routes/auth');
const userRoutes = require('./server/routes/users');
const postRoutes = require('./server/routes/posts');
const commentRoutes = require('./server/routes/comments.js');
App.use('/auth', authRoutes);
App.use('/users', userRoutes);
App.use('/posts', postRoutes);
App.use('/comments', commentRoutes);
App.use(express.static(path.resolve(__dirname, 'public')));
// Always return the main index.html, so react-router render the route in the client
App.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'public', 'index.html'));
});
const port = process.env.PORT || 8080;
App.listen(port, (req, res) => {
console.log('server up and running at ' + port);
});