'use strict';

var fs = require('fs'),
    path = require('path'),
    route = require('../../vendor/router');

module.exports = function (app) {
    /* Load All Routes */
    route.setApp(app);

    function recursiveRoutes(folderName) {
        var normalizedPath = path.join(__dirname, folderName);

        fs.readdirSync(normalizedPath).forEach(function (file) {
            var pathName = path.join(normalizedPath, file);
            var stat = fs.lstatSync(pathName);

            if (stat.isDirectory()) {
                recursiveRoutes(folderName + '/' + file);
            } else if (file.indexOf('.routes') >= 0) {
                var name = pathName.replace('.js', '').replace(/\\/g, '/');
                require(name)(app);
            }
        });
    }

    recursiveRoutes('./../../modules');

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

@@ -60,24 +60,73 @@
 e('path'),%0D%0A
+    root = path.dirname(require.main.filename),%0D%0A
     route = 
@@ -137,14 +137,16 @@
 ire(
-'../..
+root + '
 /ven
@@ -283,89 +283,16 @@
 tes(
-folderName
+dir
 ) %7B%0D%0A
-        var normalizedPath = path.join(__dirname, folderName);%0D%0A%0D%0A
     
@@ -310,30 +310,19 @@
 dirSync(
-normalizedPath
+dir
 ).forEac
@@ -383,22 +383,11 @@
 oin(
-normalizedPath
+dir
 , fi
@@ -517,18 +517,11 @@
 tes(
-folderName
+dir
  + '
@@ -764,16 +764,16 @@
 tes(
-'./../..
+root + '
 /mod

update routes