Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

app.js

By: Gloorian on Feb 3rd, 2012  |  syntax: JavaScript  |  size: 1.40 KB  |  hits: 91  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. /**
  3.  * Module dependencies.
  4.  */
  5.  
  6. var express = require('express'),
  7.     ejs = require('ejs'),
  8.     routes = require('./routes'),
  9.     mongoose = require('mongoose'),
  10.     db = require('./db');
  11.  
  12. var app = module.exports = express.createServer();
  13.  
  14. // Configuration
  15.  
  16.  
  17. app.configure(function(){
  18.     app.use(express.favicon());
  19.     app.register('.html', ejs);
  20.     app.set('view engine', 'html');
  21.     app.set('views', __dirname + '/views');
  22.     app.use(express.bodyParser());
  23.     app.use(express.cookieParser());
  24.     app.use(express.session({"secret": "keystringgloo"}));
  25.     app.use(express.methodOverride());
  26.     app.use(express.static(__dirname + '/public'));
  27.     app.use(app.router);
  28. });
  29.  
  30. app.configure('development', function(){
  31.   app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
  32. });
  33.  
  34. app.configure('production', function(){
  35.   app.use(express.errorHandler());
  36. });
  37.  
  38. function requireLogin (req, res, next) {
  39.   if (req.session.username) {
  40.     next();
  41.   } else {
  42.     res.redirect("/login");
  43.   }
  44. }
  45.  
  46.  
  47. // Routes
  48.  
  49. app.get('/', routes.index);
  50.  
  51. app.get('/signup', routes.signup_get);
  52.  
  53. app.post('/signup', routes.signup_post);
  54.  
  55. app.get('/logout', routes.logout);
  56.  
  57. app.get('/login', routes.login_get);
  58.  
  59. app.post('/login', routes.login_post);
  60.  
  61. app.listen(8000);
  62. console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);