Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. const config = require('config');
  2.  
  3. const baseOptions = {
  4. server: { socketOptions: { keepAlive: 300000, connectionTimeoutMS: 30000, maxTimeMS: 30000 } },
  5. replset: { socketOptions: { keepAlive: 300000, connectionTimeoutMS: 30000, maxTimeMS: 30000 } },
  6. };
  7.  
  8. const mongooseOptions = () => {
  9. if (!config.has('dbSslCert')) return baseOptions;
  10.  
  11. return Object.assign({
  12. mongos: {
  13. ssl: true,
  14. sslValidate: true,
  15. sslCA: [new Buffer(config.get('dbSslCert'))],
  16. },
  17. }, baseOptions);
  18. };
  19.  
  20.  
  21. const connection = mongoose.createConnection(config.db, mongooseOptions());
  22.  
  23. connection.on('disconnected', () => {
  24. // This gets consoled right before our app becomes unresponsive
  25. console.error('DATABASE: DISCONNECTED');
  26. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement