'use strict';

/**
 * Modules
 */
const express = require('express');
const identityDesk = require('../../');
const path = require('path');

// constants

const CONFIG_PATH = path.resolve(__dirname, '.identity-desk.yml'); // or you can just put .identity-desk.yml/json in your application root folder


const app = express();
module.exports = app;

// configuration

process.env.DATABASE_URL = 'sqlite://:memory:';
process.env.SESSION_SECRET = 'my secret';
app.use(identityDesk.express(CONFIG_PATH));

function restrict(req, res, next) {
  if (req.isAuthenticated()) {
    next();
  } else {
    res.redirect('/login');
  }
}

app.get('/', function(req, res) {
  res.redirect('/login');
});

app.get('/restricted', restrict, function(req, res) {
  res.send('Wahoo! restricted area, click to <a href="/logout">logout</a>');
});

app.get('/logout', function(req, res) {
  req.logout();
});

app.get('/login', function(req, res) {
  res.sendFile(path.resolve(__dirname, 'login.html'));
});

/* istanbul ignore next */
if (!module.parent) {
  app.listen(3000);
  console.log('Express started on port 3000');
}
@@ -138,20 +138,70 @@
 );%0A%0A
-// 
 const
-ants
+ app = express();%0Amodule.exports = app;%0A%0A// configuration
 %0A%0Aco
@@ -348,74 +348,8 @@
 der%0A
-%0A%0Aconst app = express();%0Amodule.exports = app;%0A%0A// configuration%0A%0A
 proc

Clean up `examples/local` code