"use strict";

var os = require("os"),
    path = require("path"),
    express = require("express"),
    routes = require("./routes");

var app = express(),
    hostname = os.hostname(),
    port = process.env.CONPA_PORT || 8080,
    documentRoot = path.resolve(__dirname, "../client"),
    nodeModules = path.resolve(__dirname, "../../node_modules/"),
    liveUrl = process.env.CONPA_LIVE_URL,
    testingUrl = process.env.CONPA_TEST_URL;

if (!liveUrl && !testingUrl) {
    throw new Error("CONPA_LIVE_URL and CONPA_TEST_URL not defined.");
}

process.on("uncaughtException", function (err) {
    console.log(err.stack);
});

app.get("/status", function (req, res) {
    res.send("ConPA is running on " + hostname + " on " + process.version);
});

app.use(express.static(documentRoot));
app.use("/node_modules", express.static(nodeModules));

routes.configure(app, {
    crm: {
        liveDomain: hostname,
        // liveDomain: "foo.com",
        liveUrl: liveUrl,
        liveDb: "conpa",
        testingUrl: testingUrl,
        testingDb: "conpa-staging",
        design: "ConPA"
    }
});

app.listen(port, function () {
    console.log("ConPA document root is " + documentRoot);
    console.log("ConPA node_modules root is " + nodeModules);
    console.log("ConPA listening on http://" + hostname + ":" + port);
});

@@ -398,16 +398,43 @@
 LIVE_URL
+ %7C%7C %22http://localhost:5984%22
 ,%0D%0A    t
@@ -475,118 +475,36 @@
 _URL
-;%0D%0A%0D%0Aif (!liveUrl && !testingUrl) %7B%0D%0A    throw new Error(%22CONPA_LIVE_URL and CONPA_TEST_URL not defined.%22);%0D%0A%7D
+ %7C%7C %22http://localhost:5984%22;
 %0D%0A%0D%0A

Add local db url.