//////////////////////////////////////////////////////////////////////////////
var os      = require("os"),
    path    = require("path"),

    // External deps
    express = require("express"),
    _       = require("underscore")._,

    // Setup app instance
    app = express(),

    // Grab app settings
    SETTINGS = require("./config.json");


//////////////////////////////////////////////////////////////////////////////
// Fix up some settings like the url etc, also
// default params for required vars
SETTINGS.url  = "http://" + os.hostname();
SETTINGS.port = SETTINGS.port || 1234;


//////////////////////////////////////////////////////////////////////////////
// Configure the express app
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "templates"));
app.set("trust proxy", true);

// Point _ to the app locals so we can refer to it from
// the ejs templates
app.locals._ = _;


//////////////////////////////////////////////////////////////////////////////
// Define application routes
var middleware = require("./app/middleware.js")(SETTINGS);
var handlers   = require("./app/route_handlers.js")(SETTINGS);
require("./app/routes.js")(app, middleware, handlers);


//////////////////////////////////////////////////////////////////////////////
// Start server
console.log("\nServer up at " + SETTINGS.url + ":" + SETTINGS.port);
app.listen(SETTINGS.port);

@@ -131,16 +131,45 @@
 %22path%22),
+%0A    fs      = require(%22fs%22),
 %0A%0A    //
@@ -1401,24 +1401,421 @@
 .listen(SETTINGS.port);%0A
+%0A%0A//////////////////////////////////////////////////////////////////////////////%0A// Validate that all the projects have a folder representing them%0A_.each(SETTINGS.projects, function(project) %7B%0A    fs.exists(project.path, function(exists) %7B%0A        if (!exists) %7B%0A            console.log(%22Warning, path: %22 + project.path + %22 does not exist (project: %22 + project.name + %22).%22);%0A        %7D%0A    %7D);%0A%7D);%0A

add validation of project paths, this is useful when we move stuff and forget about the sink