Permalink
Browse files

🎨 Add analytics and update dependencies

  • Loading branch information...
ehdsouza committed Aug 28, 2017
1 parent daf6508 commit 558ab55f3742dd4fabecd5b0e8aac415b5807474
Showing with 7,748 additions and 234 deletions.
  1. +1 −1 .eslintignore
  2. +0 −30 .eslintrc
  3. +11 −0 .eslintrc.yml
  4. +2 −2 README.md
  5. +23 −8 app.js
  6. +4 −6 casper-runner.js
  7. +2 −2 config/error-handler.js
  8. +1 −2 config/express.js
  9. +1 −1 config/security.js
  10. +7,438 −0 package-lock.json
  11. +32 −27 package.json
  12. +38 −0 public/js/analytics.js
  13. +0 −7 public/js/ga.js
  14. +1 −1 server.js
  15. +1 −5 test/integration/test.mainpage.js
  16. +3 −7 test/unit/test.express.js
  17. +168 −115 views/demo.jsx
  18. +14 −4 views/index.jsx
  19. +7 −15 views/layout.jsx
  20. +1 −1 voices.js
View
@@ -1,2 +1,2 @@
coverage
public/js/ga.js
public/js/analytics.js
View

This file was deleted.

Oops, something went wrong.
View
@@ -0,0 +1,11 @@
extends: airbnb
env:
browser: true
node: true
mocha: true
rules:
global-require: 0
no-console: 0
react/forbid-prop-types: 1
react/no-multi-comp: 0
jsx-a11y/media-has-caption: 0
View
@@ -139,6 +139,6 @@ This data is collected from the `package.json` file in the sample application an
[deploy_track_url]: https://github.com/cloudant-labs/deployment-tracker
[cloud_foundry]: https://github.com/cloudfoundry/cli
[getting_started]: https://www.ibm.com/watson/developercloud/doc/common/index.html
[service_url]: http://www.ibm.com/watson/developercloud/text-to-speech.html
[service_url]: https://www.ibm.com/watson/services/text-to-speech/
[docs]: http://www.ibm.com/watson/developercloud/text-to-speech/
[sign_up]: https://console.ng.bluemix.net/registration/
[sign_up]: https://console.bluemix.net/registration/?target=/catalog/services/text-to-speech/
View
31 app.js
@@ -13,15 +13,34 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint no-param-reassign: "off" */
const express = require('express');
const app = express();
const TextToSpeechV1 = require('watson-developer-cloud/text-to-speech/v1');
// Bootstrap application settings
require('./config/express')(app);
const getFileExtension = (acceptQuery) => {
const accept = acceptQuery || '';
switch (accept) {
case 'audio/ogg;codecs=opus':
case 'audio/ogg;codecs=vorbis':
return 'ogg';
case 'audio/wav':
return 'wav';
case 'audio/mpeg':
return 'mpeg';
case 'audio/webm':
return 'webm';
case 'audio/flac':
return 'flac';
default:
return 'mp3';
}
};
const textToSpeech = new TextToSpeechV1({
// If unspecified here, the TEXT_TO_SPEECH_USERNAME and
// TEXT_TO_SPEECH_PASSWORD env properties will be checked
@@ -32,7 +51,7 @@ const textToSpeech = new TextToSpeechV1({
app.get('/', (req, res) => {
res.render('index', {
BLUEMIX_ANALYTICS: process.env.BLUEMIX_ANALYTICS,
bluemixAnalytics: !!process.env.BLUEMIX_ANALYTICS,
});
});
@@ -43,11 +62,7 @@ app.get('/api/synthesize', (req, res, next) => {
const transcript = textToSpeech.synthesize(req.query);
transcript.on('response', (response) => {
if (req.query.download) {
if (req.query.accept && req.query.accept === 'audio/wav') {
response.headers['content-disposition'] = 'attachment; filename=transcript.wav';
} else {
response.headers['content-disposition'] = 'attachment; filename=transcript.ogg';
}
response.headers['content-disposition'] = `attachment; filename=transcript.${getFileExtension(req.query.accept)}`;
}
});
transcript.on('error', next);
@@ -60,7 +75,7 @@ app.get('/api/voices', (req, res, next) => {
if (error) {
return next(error);
}
res.json(voices);
return res.json(voices);
});
});
View
@@ -14,21 +14,19 @@
* limitations under the License.
*/
require('dotenv').config();
if (!process.env.TEXT_TO_SPEECH_USERNAME) {
// eslint-disable-next-line
console.log('Skipping integration tests because TEXT_TO_SPEECH_USERNAME is null');
return;
process.exit(0);
}
require('dotenv').config();
const spawn = require('child_process').spawn;
const app = require('./app');
const port = 3000;
const server = app.listen(port, () => {
// eslint-disable-next-line no-console
console.log('Server running on port: %d', port);
function kill(code) {
View
@@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint no-unused-vars: "off" */
module.exports = function (app) {
module.exports = (app) => {
// catch 404 and forward to error handler
app.use((req, res, next) => {
const err = new Error('Not Found');
@@ -26,6 +25,7 @@ module.exports = function (app) {
});
// error handler
// eslint-disable-next-line
app.use((err, req, res, next) => {
const error = {
code: err.code || 500,
View
@@ -14,15 +14,14 @@
* limitations under the License.
*/
// Module dependencies
const express = require('express');
const bodyParser = require('body-parser');
const expressBrowserify = require('express-browserify');
const path = require('path');
const morgan = require('morgan');
module.exports = function (app) {
module.exports = (app) => {
app.enable('trust proxy');
app.set('view engine', 'jsx');
app.engine('jsx', require('express-react-views').createEngine());
View
@@ -20,7 +20,7 @@ const secure = require('express-secure-only');
const helmet = require('helmet');
const rateLimit = require('express-rate-limit');
module.exports = function (app) {
module.exports = (app) => {
app.use(secure());
app.use(helmet());
Oops, something went wrong.

0 comments on commit 558ab55

Please sign in to comment.