Advertisement
Guest User

index.js

a guest
Oct 15th, 2015
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. var express = require('express');
  2. var engines = require('consolidate');
  3. var mongoose = require('mongoose');
  4. var passport = require('passport');
  5. var cookieParser = require('cookie-parser');
  6. var bodyParser = require('body-parser');
  7. var session = require('express-session');
  8. var flash = require('connect-flash');
  9. var port = 3700;
  10.  
  11. var app = express();
  12.  
  13. // view engine
  14. app.set('views', __dirname + '/views/');
  15. app.set('view engine', 'handlebars');
  16. var hbs = require('handlebars');
  17.  
  18. // custom helper for numbering scoreboard by
  19. // adding index += 1
  20. hbs.registerHelper("inc", function(value, options)
  21. {
  22. return parseInt(value) + 1;
  23. });
  24. app.engine('handlebars', engines.handlebars);
  25.  
  26. app.use(express.static(__dirname + '/public'));
  27. app.use(bodyParser.json());
  28. app.use(bodyParser.urlencoded({ extended: true }));
  29.  
  30.  
  31. app.use(cookieParser()); // read cookies (needed for auth)
  32.  
  33.  
  34. // required for passport
  35. app.use(session({ secret: 'cjisadickler', resave: true, saveUninitialized: true})); // session secret
  36.  
  37. // used to pass session to template if necessary
  38. // app.use(function(req, res, next) {
  39. // res.locals.session = req.session;
  40. // next();
  41. // });
  42. app.use(passport.initialize());
  43. app.use(passport.session()); // persistent login sessions
  44.  
  45. // Using the flash middleware provided by connect-flash to store messages in session
  46. // and displaying in templates.
  47. var flash = require('connect-flash');
  48. app.use(flash());
  49.  
  50. //initialize passport
  51. var initPassport = require('./passport/init');
  52. initPassport(passport);
  53.  
  54. var routes = require('./routes/index')(passport);
  55. app.use('/', routes);
  56.  
  57. // required for mongoose
  58. var dbConfig = require('./db');
  59. mongoose.connect(dbConfig.url);
  60.  
  61. // socket.io
  62. var io = require('socket.io').listen(app.listen(port));
  63. require('./routes/socket.js')(io);
  64. require('./bot/bot.js')(io);
  65.  
  66. module.exports = app;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement