SHARE
TWEET

Untitled

a guest Jul 17th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express');
  2. const mongoose = require('mongoose');
  3. const bodyParser = require('body-parser');
  4. const passport = require('passport');
  5. const path = require('path');
  6. const cors = require('cors');
  7.  
  8. //Api routes
  9. const users = require('./routes/api/usuario');
  10. const alumno = require('./routes/api/alumno');
  11. const personal = require('./routes/api/personal');
  12. const zonas = require('./routes/api/zonas');
  13. const sepomex = require('./routes/api/sepomex');
  14.  
  15. const app = express();
  16.  
  17. app.use(cors());
  18. //Body parser middleware
  19. app.use(bodyParser.urlencoded({ extended: false }));
  20. app.use(bodyParser.json());
  21.  
  22. //Db config
  23. const db = process.env.NODE_ENV === "production" ? require('./config/keys').mongoURIProd : require('./config/keys').mongoURIDev;
  24.  
  25. //connect to mongo DB
  26. mongoose
  27.     .connect(db, { useNewUrlParser: true })
  28.     .then(() => console.log('MongoDB Connected'))
  29.     .catch(err => console.log(err));
  30.  
  31. //passport middleware
  32. app.use(passport.initialize());
  33. //passport config
  34. require('./config/passport')(passport);
  35.  
  36. //Use routes
  37.  
  38. app.use('/api/usuario', users);
  39. app.use('/api/alumno', alumno);
  40. app.use('/api/personal', personal);
  41. app.use('/api/zonas', zonas);
  42. app.use('/api/sepomex', sepomex);
  43.  
  44. console.log(process.env.NODE_ENV)
  45.  
  46. //serve static assets to production
  47. if (process.env.NODE_ENV === "production") {
  48.     //static folder
  49.     app.use(express.static("client/build"));
  50.  
  51.     app.get('/*', (req, res) => {
  52.         res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
  53.     })
  54. }
  55.  
  56.  
  57. const port = process.env.PORT || 5000;
  58.  
  59.  
  60. app.listen(port, () => {
  61.     console.log(`Server running on port ${port}`);
  62. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top