Facebook
From Eratic Madrill, 3 Years ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 86
  1. require('dotenv').config()
  2.  
  3. const express = require('express');
  4. const bodyParser = require('body-parser');
  5.  
  6. // create express app
  7. const app = express();
  8.  
  9. // parse application/x-www-form-urlencoded
  10. app.use(bodyParser.urlencoded({ extended: true }))
  11.  
  12. // parse application/json
  13. app.use(bodyParser.json())
  14.  
  15. // Configuring the database
  16. const dbConfig = require('./config/database.config.js');
  17. const mongoose = require('mongoose');
  18.  
  19. const cors = require('cors');
  20.  
  21. mongoose.Promise = global.Promise;
  22.  
  23. // Connecting to the database
  24. mongoose.connect(process.env.MONGODB_URI || dbConfig.url, {
  25.     useNewUrlParser: true
  26. }).then(() => {
  27.     console.log("Successfully connected to the database");
  28. }).catch(err => {
  29.     console.log('Could not connect to the database. Exiting now...', err);
  30.     process.exit();
  31. });
  32.  
  33. // define a simple route
  34. app.get('/', (req, res) => {
  35.     res.json({"message": "Welcome to EasyDonations application. Take donations quickly. Organize and keep track of all your donations."});
  36. });
  37.  
  38. // Then use it before your routes are set up:
  39. app.use(cors({credentials: true, origin: true}));
  40.  
  41. require('./app/models/timeframe.js');
  42. require('./app/routes/institution.routes.js')(app);
  43. require('./app/routes/offer.routes.js')(app);
  44. require('./app/routes/request.routes.js')(app);
  45. require('./app/routes/user.routes.js')(app);
  46. require('./app/routes/volunteer.routes.js')(app);
  47. require('./app/routes/donation.routes.js')(app);
  48.  
  49. // listen for requests
  50. app.listen(process.env.PORT || 3000, () => {
  51.     console.log("Server is listening on port 3000");
  52. });
  53.  
  54. app.use(require('forest-express-mongoose').init({
  55.     modelsDir: __dirname + '/app/models',
  56.     envSecret: 'xxx', // I'm hiding my key, but it is the one I get at the development environment of forest
  57.     authSecret: 'testeando', // I think I can put any string for development purposes, otherwise I don't know were to get authSecret
  58.     mongoose: require('mongoose'),
  59. }));
captcha