Skip to content

Instantly share code, notes, and snippets.

@rlemon

rlemon/server.js Secret

Last active August 29, 2015 13:57
Show Gist options
  • Save rlemon/a2fa12bfd550ef5a0e7b to your computer and use it in GitHub Desktop.
Save rlemon/a2fa12bfd550ef5a0e7b to your computer and use it in GitHub Desktop.
var express = require('express'),
passport = require('passport');
var PORT = 3000;
var app = express();
require('modules/authentication');
app.configure(function() {
app.use(express.static(__dirname + 'public'));
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.session({ secret: 'shhh it is a secret' }));
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
});
app.get('/', function(req,res) {
if( !req.user ) {
res.redirect('/login');
}
res.sendFile(__dirname + '/views/dashboard.html');
});
app.get('/login', function(req,res) {
if( req.user ) {
res.redirect('/');
}
res.sendFile(__dirname + '/views/login.html');
});
app.post('/login', passport.authenticate('local', { failureRedirect: '/login?failed=true' }, function(req, res) {
res.redirect('/');
});
app.listen(PORT);
console.log("server started and listening on port " + PORT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment