Permalink
Browse files

Migrated express 3 to 4

  • Loading branch information...
1 parent af48221 commit c3f54abb60d220a3531d0c77f553e01842dc6dc8 @ancasicolica ancasicolica committed Jun 7, 2016
Showing with 137 additions and 117 deletions.
  1. +1 −0 .gitignore
  2. +40 −39 app.js
  3. +16 −15 config/config.js
  4. +58 −55 config/routes.js
  5. +22 −8 package.json
View
@@ -1,3 +1,4 @@
/node_modules
/bower_components
/public
+/.idea
View
@@ -1,67 +1,68 @@
-var express = require('express'),
- http = require('http'),
- path = require('path'),
- passport = require("passport");
+const express = require('express');
+const http = require('http');
+const path = require('path');
+const passport = require("passport");
+const morgan = require('morgan');
+const cookieParser = require('cookie-parser');
+const bodyParser = require('body-parser');
+const session = require('express-session');
+const methodOverride = require('method-override');
+const errorhandler = require('errorhandler');
-var env = process.env.NODE_ENV || 'development',
- config = require('./config/config')[env];
+var env = process.env.NODE_ENV || 'development';
+const config = require('./config/config')[env];
+
+console.log('Using configuration', config);
require('./config/passport')(passport, config);
var app = express();
-app.configure(function () {
- app.set('port', config.app.port);
- app.set('views', __dirname + '/app/views');
- app.set('view engine', 'jade');
- app.use(express.logger('dev'));
- app.use(express.cookieParser());
- app.use(express.bodyParser());
- app.use(express.session(
- {
- secret: 'this shit hits'
- }));
- app.use(passport.initialize());
- app.use(passport.session());
- app.use(express.methodOverride());
- app.use(app.router);
- app.use(express.static(path.join(__dirname, 'public')));
-});
+app.set('port', config.app.port);
+app.set('views', __dirname + '/app/views');
+app.set('view engine', 'jade');
+app.use(morgan('combined'));
+app.use(cookieParser());
+app.use(bodyParser.json());
+app.use(bodyParser.urlencoded({extended: false}));
+app.use(session(
+ {
+ resave: true,
+ saveUninitialized: true,
+ secret: 'this shit hits'
+ }));
+app.use(passport.initialize());
+app.use(passport.session());
+app.use(methodOverride());
+app.use(express.static(path.join(__dirname, 'public')));
-app.configure('development', function () {
- console.log ("Development mode.");
- app.use(express.errorHandler());
-});
-app.configure ('production', function () {
- console.log ("Production mode.");
-});
-app.use(function(err, req, res, next) {
+app.use(function (err, req, res, next) {
res.status(err.status || 500);
- res.render('500', { error: err });
+ res.render('500', {error: err});
});
-
-app.use(function(req, res, next){
+/*
+app.use(function (req, res, next) {
res.status(404);
if (req.accepts('html')) {
res.render('404',
{
- url : req.url
+ url: req.url
});
return;
}
if (req.accepts('json')) {
- res.send({ error: 'Not found' });
+ res.send({error: 'Not found'});
return;
}
res.type('txt').send('Not found');
});
-
+*/
require('./config/routes')(app, config, passport);
-http.createServer(app).listen(app.get('port'), function () {
- console.log("Express server listening on port " + app.get('port'));
+app.listen(app.get('port'), function () {
+ console.log("Express server listening on port " + app.get('port'));
});
View
@@ -1,16 +1,17 @@
module.exports = {
- development : {
- app : {
- name : 'Passport SAML strategy example',
- port : process.env.PORT || 3000
- },
- passport: {
- strategy : 'saml',
- saml : {
- path : '/login/callback',
- entryPoint : 'https://openidp.feide.no/simplesaml/saml2/idp/SSOService.php',
- issuer : 'passport-saml'
- }
- }
- }
-}
+ development: {
+ app: {
+ name: 'Passport SAML strategy example',
+ port: process.env.PORT || 3000
+ },
+ passport: {
+ strategy: 'saml',
+ saml: {
+ path: process.env.SAML_PATH || '/login/callback',
+ entryPoint: process.env.SAML_ENTRY_POINT || 'https://openidp.feide.no/simplesaml/saml2/idp/SSOService.php',
+ issuer: 'passport-saml',
+ cert: process.env.SAML_CERT || null
+ }
+ }
+ }
+};
View
@@ -1,55 +1,58 @@
-module.exports = function(app, config, passport) {
- app.get("/", function(req, res) {
- if(req.isAuthenticated()) {
- res.render("home",
- {
- user : req.user
- });
- } else {
- res.render("home",
- {
- user : null
- });
- }
- });
-
- app.get("/login",
- passport.authenticate(config.passport.strategy,
- {
- successRedirect : "/",
- failureRedirect : "/login",
- })
- );
-
- app.post('/login/callback',
- passport.authenticate(config.passport.strategy,
- {
- failureRedirect: '/',
- failureFlash: true
- }),
- function(req, res) {
- res.redirect('/');
- }
- );
-
- app.get("/signup", function (req, res) {
- res.render("signup");
- });
-
- app.get("/profile", function(req, res) {
- if(req.isAuthenticated()){
- res.render("profile",
- {
- user : req.user
- });
- } else {
- res.redirect("/login");
- }
- });
-
- app.get('/logout', function(req, res) {
- req.logout();
- // TODO: invalidate session on IP
- res.redirect('/');
- });
-}
+
+module.exports = function (app, config, passport) {
+
+ app.get("/", function (req, res) {
+ if (req.isAuthenticated()) {
+ res.render("home",
+ {
+ user: req.user
+ });
+ } else {
+ res.render("home",
+ {
+ user: null
+ });
+ }
+ });
+
+ app.get("/login",
+ passport.authenticate(config.passport.strategy,
+ {
+ successRedirect: "/",
+ failureRedirect: "/login",
+ })
+ );
+
+ app.post(config.passport.saml.path,
+ passport.authenticate(config.passport.strategy,
+ {
+ failureRedirect: '/',
+ failureFlash: true
+ }),
+ function (req, res) {
+ res.redirect('/');
+ }
+ );
+
+ app.get("/signup", function (req, res) {
+ res.render("signup");
+ });
+
+ app.get("/profile", function (req, res) {
+ if (req.isAuthenticated()) {
+ res.render("profile",
+ {
+ user: req.user
+ });
+ } else {
+ res.redirect("/login");
+ }
+ });
+
+ app.get('/logout', function (req, res) {
+ req.logout();
+ // TODO: invalidate session on IP
+ res.redirect('/');
+ });
+
+};
View
@@ -7,6 +7,12 @@
"email": "me@gbraad.nl",
"url": "http://gbraad.nl"
},
+ "contributors": [
+ {
+ "name": "Christian Kuster",
+ "email": "git@kusti.ch"
+ }
+ ],
"keywords": [
"saml",
"sso"
@@ -17,16 +23,24 @@
},
"scripts": {
"start": "nodemon app.js",
- "test": ""
+ "test": "",
+ "postinstall": "bower install"
},
"dependencies": {
- "express": "3.1.0",
- "jade": "*",
- "nodemon": "*",
- "passport": "*",
- "passport-saml": "*"
+ "body-parser": "1.15.1",
+ "cookie-parser": "1.4.3",
+ "errorhandler": "1.4.3",
+ "express": "4.13.4",
+ "express-session": "1.13.0",
+ "jade": "1.11.0",
+ "method-override": "2.3.6",
+ "morgan": "1.7.0",
+ "nodemon": "1.9.2",
+ "passport": "0.3.2",
+ "passport-saml": "0.15.0"
},
"engines": {
- "node": ">= 0.10.0"
- }
+ "node": ">= 4.0.0"
+ },
+ "license": "MIT"
}

0 comments on commit c3f54ab

Please sign in to comment.