/**
 * Copyright 2014 IBM Corp. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

'use strict';

var express = require('express'),
  app = express(),
  bluemix = require('./config/bluemix'),
  watson = require('watson-developer-cloud'),
  extend = require('util')._extend;

// Bootstrap application settings
require('./config/express')(app);

// if bluemix credentials exists, then override local
var credentials = extend({
  version: 'v1',
  username: '<username>',
  password: '<password>',
  headers: { 'Accept': 'audio/ogg; codecs=opus' }
}, bluemix.getServiceCreds('text_to_speech')); // VCAP_SERVICES

// Create the service wrapper
var textToSpeech = new watson.text_to_speech(credentials);

// render index page
app.get('/', function(req, res) {
  res.render('index');
});

app.get('/synthesize', function(req, res) {
  var transcript = textToSpeech.synthesize(req.query);

  transcript.on('response', function(response) {
    if (req.query.download) {
      response.headers['content-disposition'] = 'attachment; filename=transcript.ogg';
    }
  });
  transcript.pipe(res);
});

var port = process.env.VCAP_APP_PORT || 3000;
app.listen(port);
console.log('listening at:', port);

@@ -769,315 +769,243 @@
 '),%0A
-  extend = require('util')._extend;%0A%0A// Bootstrap application settings%0Arequire('./config/express')(app);%0A%0A// if bluemix credentials exists, then override local%0Avar credentials = extend(%7B%0A  version: 'v1',%0A  username: '%3Cusername%3E',%0A  password: '%3Cpassword%3E',%0A  headers: %7B 'Accept': 'audio/ogg; codecs=opus' %7D%0A%7D
+%09// environmental variable points to demo's json config file%0A%09config = require(process.env.WATSON_OPTIONS_FILE),%0A  extend = require('util')._extend;%0A%0A// if bluemix credentials exists, then override local%0Avar credentials = extend(config
 , bl
@@ -1049,25 +1049,8 @@
 '));
- // VCAP_SERVICES
 %0A%0A//
@@ -1144,391 +1144,71 @@
 %0A// 
-render index page%0Aapp.get('/', function(req, res) %7B%0A  res.render('index');%0A%7D);%0A%0Aapp.get('/synthesize', function(req, res) %7B%0A  var transcript = textToSpeech.synthesize(req.query);%0A%0A  transcript.on('response', function(response) %7B%0A    if (req.query.download) %7B%0A      response.headers%5B'content-disposition'%5D = 'attachment; filename=transcript.ogg';%0A    %7D%0A  %7D);%0A  transcript.pipe(res);%0A%7D
+Configure express%0Arequire('./config/express')(app, textToSpeech
 );%0A%0A
@@ -1302,13 +1302,12 @@
 at:', port);
-%0A

Add updated Express app file