SHARE
TWEET

Untitled

a guest Dec 8th, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const mongoose = require('mongoose');
  2. require('./users');
  3. require('./car_brands');
  4. const brands_models_ctrl = require('../controllers/brands_models');
  5.  
  6. var dbURI = 'mongodb://localhost/Fuelly';
  7. if (process.env.NODE_ENV === 'production') {
  8.     dbURI = process.env.MONGODB_CLOUD_URI;
  9.     // var dbURI = 'mongodb+srv://admin:fuelly312@fuelly-vju8d.mongodb.net/test?retryWrites=true&w=majority';
  10. }
  11. mongoose.connect(dbURI, {
  12.     useNewUrlParser: true,
  13.     useCreateIndex: true,
  14.     useUnifiedTopology: true,
  15.     useFindAndModify: false
  16. });
  17.  
  18. mongoose.connection.on('connected', () => {
  19.     console.log(`Mongoose je povezan na ${dbURI}.`);
  20.     //delete and then import all brands with their models
  21.     brands_models_ctrl.deleteBrandsModels();
  22.     brands_models_ctrl.importBrandsModels();
  23. });
  24.  
  25. mongoose.connection.on('error', napaka => {
  26.     console.log('Mongose napaka pri povezavi: ', napaka);
  27. });
  28.  
  29. mongoose.connection.on('disconnected', () => {
  30.     console.log('Mongoose ni povezan.');
  31. });
  32.  
  33. const pravilnaUstavitev = (sporocilo, povratniKlic) => {
  34.     mongoose.connection.close(() => {
  35.         console.log(`Mongoose je zaprl povezavo preko '${sporocilo}'.`);
  36.         povratniKlic();
  37.     });
  38. };
  39.  
  40. // Ponovni zagon nodemon
  41. process.once('SIGUSR2', () => {
  42.     pravilnaUstavitev('nodemon ponovni zagon', () => {
  43.         process.kill(process.pid, 'SIGUSR2');
  44.     });
  45. });
  46.  
  47. // Izhod iz aplikacije
  48. process.on('SIGINT', () => {
  49.     pravilnaUstavitev('izhod iz aplikacije', () => {
  50.         process.exit(0);
  51.     });
  52. });
  53.  
  54. // Izhod iz aplikacije na Heroku
  55. process.on('SIGTERM', () => {
  56.     pravilnaUstavitev('izhod iz aplikacije na Heroku', () => {
  57.         process.exit(0);
  58.     });
  59. });
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
 
Top