var express = require('express'),
    app     = express(),
    bodyParser = require('body-parser');
    mongoose   = require('mongoose');

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

var port = process.env.PORT || process.env.OPENSHIFT_NODEJS_PORT || 8080,
    ip   = process.env.IP   || process.env.OPENSHIFT_NODEJS_IP || '0.0.0.0',
    mongoURL = process.env.OPENSHIFT_MONGODB_DB_URL || process.env.MONGO_URL,
    mongoURLLabel = "";

if (mongoURL == null && process.env.DATABASE_SERVICE_NAME) {
      var mongoServiceName = process.env.DATABASE_SERVICE_NAME.toUpperCase(),
          mongoHost = process.env[mongoServiceName + '_SERVICE_HOST'],
          mongoPort = process.env[mongoServiceName + '_SERVICE_PORT'],
          mongoDatabase = process.env[mongoServiceName + '_DATABASE'],
          mongoPassword = process.env[mongoServiceName + '_PASSWORD']
          mongoUser = process.env[mongoServiceName + '_USER'];

  if (mongoHost && mongoPort && mongoDatabase) {
        mongoURLLabel = mongoURL = 'mongodb://';
        if (mongoUser && mongoPassword) {
          mongoURL += mongoUser + ':' + mongoPassword + '@';
        }
        // Provide UI label that excludes user id and pw
        mongoURLLabel += mongoHost + ':' + mongoPort + '/' + mongoDatabase;
        mongoURL += mongoHost + ':' +  mongoPort + '/' + mongoDatabase;

  }
}

var mongoUser =  process.env.MONGODB_USER;
    mongoDatabase = process.env.MONGODB_DATABASE;
    mongoPassword = process.env.MONGODB_PASSWORD;
    mongoHost = process.env.TAXCALCDB_SERVICE_HOST;
    mongoPort = process.env.TAXCALCDB_SERVICE_PORT;
    mongoURL = 'mongodb://';

mongoURL += mongoUser + ':' + mongoPassword + '@';
mongoURL += mongoHost + ':' +  mongoPort + '/' + mongoDatabase;

mongoose.connect(mongoURL);

var Transaction = require('./models/transaction');

var route = express.Router();

route.route('/calculate')
     .post(function(req, res) {

        var tx = new Transaction();
        tx.id = req.body.id;
        tx.amount = req.body.amount;
        var finalAmount = tx.amount + (tx.amount * .3);

        tx.save(function(e) {
            if (e)
                res.send(e);

            res.json({ finalAmount: finalAmount });
        });

    });

// All our services are under the /api context
app.use('/api', route);

// Start defining routes for our app/microservice

route.get('/', function(req, res) {
    res.json({
      status: 'up' 
    });
});

app.listen(port, ip);
console.log('Server running on http://%s:%s', ip, port);

module.exports = app;

@@ -372,1016 +372,8 @@
     
-mongoURL = process.env.OPENSHIFT_MONGODB_DB_URL %7C%7C process.env.MONGO_URL,%0A    mongoURLLabel = %22%22;%0A%0Aif (mongoURL == null && process.env.DATABASE_SERVICE_NAME) %7B%0A      var mongoServiceName = process.env.DATABASE_SERVICE_NAME.toUpperCase(),%0A          mongoHost = process.env%5BmongoServiceName + '_SERVICE_HOST'%5D,%0A          mongoPort = process.env%5BmongoServiceName + '_SERVICE_PORT'%5D,%0A          mongoDatabase = process.env%5BmongoServiceName + '_DATABASE'%5D,%0A          mongoPassword = process.env%5BmongoServiceName + '_PASSWORD'%5D%0A          mongoUser = process.env%5BmongoServiceName + '_USER'%5D;%0A%0A  if (mongoHost && mongoPort && mongoDatabase) %7B%0A        mongoURLLabel = mongoURL = 'mongodb://';%0A        if (mongoUser && mongoPassword) %7B%0A          mongoURL += mongoUser + ':' + mongoPassword + '@';%0A        %7D%0A        // Provide UI label that excludes user id and pw%0A        mongoURLLabel += mongoHost + ':' + mongoPort + '/' + mongoDatabase;%0A        mongoURL += mongoHost + ':' +  mongoPort + '/' + mongoDatabase;%0A%0A  %7D%0A%7D%0A
 %0Avar
@@ -1437,17 +1437,16 @@
 us: 'up'
- 
 %0A    %7D);

clean up junk env vars