Skip to content

Commit 3abc8a2

Browse files
committed
set up automatic deployment of examples to bluemix
1 parent f7d1592 commit 3abc8a2

File tree

10 files changed

+93
-26
lines changed

10 files changed

+93
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ doc/
1010
.env
1111
dist/*.min.js
1212
examples/static/webpack-bundle.js
13+
examples/node_modules/

.travis.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
language: node_js
22
node_js:
33
- stable
4+
sudo: required
45
before_install:
56
- export CHROME_BIN=chromium-browser
67
- export DISPLAY=:99.0
78
- sh -e /etc/init.d/xvfb start
89
script:
910
- npm test
10-
- sed -i "s/\/master\//\/$TRAVIS_BRANCH\//g" README.md # replace "master" in doc urls with current branch/tag
11+
- sed -i "s/\/master\//\/$TRAVIS_BRANCH\//g" README.md
1112
- npm run doc
1213
after_success:
1314
- jsdoc/publish.sh
1415
env:
1516
global:
16-
secure: Bx6pW0ihp3Y2dW5a8fkPhbMKsVg7MRfCzN3laN/OL7vTy2etIDXFleddE5No74HVQ1gPhkOIoRko/pHPdzWGNq69VtoCxp3AdISsuillYcaDCfRXDBSZXbHVuXsUHFQIABIdKJZZVjjwXM4oulL4OWboZ8FWV7vgOBvN4ZrXjM8LfuahSG51cPbPktqa+v/rA03iuWwC8IUDhf5w2uNPrsvtzWmj+CHcpLIgjmJWan+SiJXK/i3Wz/B74Cb0RtP9Y7zJzIGSWg8Z1VruN/f8xoNeSbMz5HM+PMhGyQJ9QXUNEqUEiXG+gwIzhAYRwBbCGyQZME5zk/y7QM0lr3/4NBzq8e6RYWlyOVLRGxlL6SvPmQ/6FrMCe9QDcMnvDvfeYhTHa6SnkqymN1hp1JnPC65zXENbEOLJH/67mQs/WoHLuuZycUK0KPC+GK6Bc45ViXotyNTttzrxHfpOV4IXQDVqB6p6tlh940ksYpetSs+8s7piUOGIcu4XtYxdnSRGX7TwKiCuuK65XWYpk+oMWhKHsOS2FTDt85+PXKFnM1fiuFD+Oppa7xyXmSUZp4C1befd7nP7F5RGSkZWdfXuCY6xAS6E7dho4clIua2yhOWtgnoMlcjjht6sFYf8OEk3eoVvnP+OO3VSHwk0VkTbI3E3fp3H8CUXVMk9woegydQ=
17+
- secure: Bx6pW0ihp3Y2dW5a8fkPhbMKsVg7MRfCzN3laN/OL7vTy2etIDXFleddE5No74HVQ1gPhkOIoRko/pHPdzWGNq69VtoCxp3AdISsuillYcaDCfRXDBSZXbHVuXsUHFQIABIdKJZZVjjwXM4oulL4OWboZ8FWV7vgOBvN4ZrXjM8LfuahSG51cPbPktqa+v/rA03iuWwC8IUDhf5w2uNPrsvtzWmj+CHcpLIgjmJWan+SiJXK/i3Wz/B74Cb0RtP9Y7zJzIGSWg8Z1VruN/f8xoNeSbMz5HM+PMhGyQJ9QXUNEqUEiXG+gwIzhAYRwBbCGyQZME5zk/y7QM0lr3/4NBzq8e6RYWlyOVLRGxlL6SvPmQ/6FrMCe9QDcMnvDvfeYhTHa6SnkqymN1hp1JnPC65zXENbEOLJH/67mQs/WoHLuuZycUK0KPC+GK6Bc45ViXotyNTttzrxHfpOV4IXQDVqB6p6tlh940ksYpetSs+8s7piUOGIcu4XtYxdnSRGX7TwKiCuuK65XWYpk+oMWhKHsOS2FTDt85+PXKFnM1fiuFD+Oppa7xyXmSUZp4C1befd7nP7F5RGSkZWdfXuCY6xAS6E7dho4clIua2yhOWtgnoMlcjjht6sFYf8OEk3eoVvnP+OO3VSHwk0VkTbI3E3fp3H8CUXVMk9woegydQ=
18+
- CF_APP=watson-speech
19+
- CF_API=https://api.ng.bluemix.net
20+
- CF_ORGANIZATION=WatsonPlatformServices
21+
- CF_SPACE=sdks
22+
23+
- secure: NDOdoAt1bjGspsU9CZl494GW9OEC9J56OCJloyfd0KGkDmKLNpYGw5eHXmJfLVqKAvldhOpjp0aNSrrwVcT2qvE2dhtYkL+a5hVMZFr7DdfOtZze/MIdCpoQhZQz8+wQa82crGgf+cTL2Y+BndkQoDk5mMo/3sAf512euHTHJXb+9DZ36ZJYIK/hVTfzZMdUUH7059rYeUADhXXcbu1Va+cJHXr2xRFI8ZEdZfZ0V1jDEqPyi/hwDYODgsTpk/4jRFlkZu2Agxq2kOETeuJYiTJ7O9Q1qhY3rSAgu/rvQK8+Y7ngTxWS8rStOOr8CNXJtmZdM0zpz6RbmQEhR5Xk4s8aX1rxPDj06/Cx7BVWKZWb7wGJETjKq/+NLv/tK9tXDVZ5oBj/H9VkUm2gWqWCKaAge9xW+wuh/LluGMZIx+pTDI94AbgIZnxP2HoALmGIvyim7AquvQqaqIqVR3XTXZUccYM5yRCkxHknZbbL/hX4GOM/I1Ue24d5wt4okkGV2R/DNWYfnajB7GZOTvK5/kn7x6bJpU0Ls9ZYW+4V0zUO/3g5KalU3Cire/dSOC7WzrL823koEgpF9KCVjtCCsj1wMZI099FTGFljqfzlVKMy4Sw4tafRjpkQQT3GLoX1CV/B4n4BDOySoGBPlM0JYiEua+J5GNpeq34n38bwn4g=
1724
before_deploy:
1825
- npm run build
26+
- npm install -g cf-blue-green
1927
deploy:
2028
- provider: releases
2129
api_key:
@@ -35,3 +43,8 @@ deploy:
3543
on:
3644
tags: true
3745
repo: watson-developer-cloud/speech-javascript-sdk
46+
- provider: script
47+
script: cd examples/ && cf-blue-green-travis
48+
on:
49+
branch: master
50+
repo: watson-developer-cloud/speech-javascript-sdk

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ API & Examples
4343

4444
The basic API is outlined below, see complete API docs at http://watson-developer-cloud.github.io/speech-javascript-sdk/master/
4545

46-
See code for several basic examples at https://github.com/watson-developer-cloud/speech-javascript-sdk/tree/master/examples/static/
46+
See several basic examples at http://watson-speech.mybluemix.net/ ([source](https://github.com/watson-developer-cloud/speech-javascript-sdk/tree/master/examples/))
4747

48-
See a live example at https://speech-to-text-demo.mybluemix.net/
48+
See a more advanced example at https://speech-to-text-demo.mybluemix.net/
4949

5050
All API methods require an auth token that must be [generated server-side](https://github.com/watson-developer-cloud/node-sdk#authorization).
5151
(See https://github.com/watson-developer-cloud/speech-javascript-sdk/tree/master/examples/ for a couple of basic examples in Node.js and Python.)

examples/.cfignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
keys/
3+
static/bower_components/jquery/src/

examples/manifest.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
declared-services:
3+
speech_to_text_sdk:
4+
label: speech_to_text
5+
plan: standard
6+
text_to_speech_sdk:
7+
label: text_to_speech
8+
plan: standard
9+
applications:
10+
- name: watson-speech
11+
buildpack: sdk-for-nodejs
12+
path: .
13+
command: npm start
14+
memory: 512M
15+
services:
16+
- speech_to_text_sdk
17+
- text_to_speech_sdk
18+
env:
19+
NODE_ENV: production

examples/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@
1010
"dotenv": "^2.0.0",
1111
"express": "^4.13.3",
1212
"express-browserify": "^1.0.2",
13+
"express-rate-limit": "^2.6.0",
14+
"express-secure-only": "^0.2.1",
1315
"object.assign": "^4.0.4",
14-
"vcap_services": "^0.1.7",
15-
"watson-developer-cloud": "^1.2.0",
16+
"vcap_services": "^0.2.0",
17+
"watson-developer-cloud": "^2.18.0",
1618
"watson-speech": "*",
1719
"webpack": "^2.2.1",
1820
"webpack-dev-middleware": "^1.10.0",
1921
"whatwg-fetch": "^1.0.0"
2022
},
23+
"engines": {
24+
"node": ">=4"
25+
},
2126
"license": "Apache-2.0"
2227
}

examples/server.js

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616

1717
'use strict';
1818

19-
var express = require('express');
20-
var app = express();
21-
var expressBrowserify = require('express-browserify');
19+
const express = require('express');
20+
const app = express();
21+
const expressBrowserify = require('express-browserify');
2222

2323
// allows environment properties to be set in a file named .env
2424
require('dotenv').load({silent: true});
2525

2626
app.use(express.static(__dirname + '/static'));
2727

2828
// set up express-browserify to serve browserify bundles for examples
29-
var isDev = app.get('env') === 'development';
29+
const isDev = app.get('env') === 'development';
3030
app.get('/browserify-bundle.js', expressBrowserify('static/browserify-app.js', {
3131
watch: isDev,
3232
debug: isDev
@@ -38,24 +38,46 @@ app.get('/audio-video-deprecated/bundle.js', expressBrowserify('static/audio-vid
3838

3939

4040
// set up webpack-dev-middleware to serve Webpack bundles for examples
41-
var webpackDevMiddleware = require('webpack-dev-middleware');
42-
var webpack = require('webpack');
43-
var webpackConfig = require('./webpack.config');
41+
const webpackDevMiddleware = require('webpack-dev-middleware');
42+
const webpack = require('webpack');
43+
const webpackConfig = require('./webpack.config');
4444

45-
var compiler = webpack(webpackConfig);
45+
const compiler = webpack(webpackConfig);
4646

4747
app.use(webpackDevMiddleware(compiler, {
4848
publicPath: '/' // Same as `output.publicPath` in most cases.
4949
}));
5050

5151

5252

53+
// on bluemix, enable rate-limiting and force https
54+
if(process.env.VCAP_SERVICES) {
55+
// enable rate-limiting
56+
const RateLimit = require('express-rate-limit');
57+
app.enable('trust proxy'); // required to work properly behind Bluemix's reverse proxy
58+
59+
const limiter = new RateLimit({
60+
windowMs: 15*60*1000, // 15 minutes
61+
max: 100, // limit each IP to 100 requests per windowMs
62+
delayMs: 0 // disable delaying - full speed until the max limit is reached
63+
});
64+
65+
// apply to /api/*
66+
app.use('/api/', limiter);
67+
68+
// force https - microphone access requires https in Chrome and possibly other browsers
69+
// (*.mybluemix.net domains all have built-in https support)
70+
const secure = require('express-secure-only');
71+
app.use(secure());
72+
}
73+
74+
5375
// token endpoints
54-
// **Warning**: these endpoints should be guarded with additional authentication & authorization for production use
76+
// **Warning**: these endpoints should probably be guarded with additional authentication & authorization for production use
5577
app.use('/api/speech-to-text/', require('./stt-token.js'));
5678
app.use('/api/text-to-speech/', require('./tts-token.js'));
5779

58-
var port = process.env.VCAP_APP_PORT || 3000;
80+
const port = process.env.VCAP_APP_PORT || 3000;
5981
app.listen(port, function() {
6082
console.log('Example IBM Watson Speech JS SDK client app & token server live at http://localhost:%s/', port);
6183
});
@@ -64,12 +86,12 @@ app.listen(port, function() {
6486
// this sets up a basic server at https://localhost3001/ using an included self-signed certificate
6587
// note: this is not suitable for production use
6688
// however bluemix automatically adds https support at http://<myapp>.mybluemix.net
67-
if (!process.env.VCAP_APP_PORT) {
68-
var fs = require('fs'),
89+
if (!process.env.VCAP_SERVICES) {
90+
const fs = require('fs'),
6991
https = require('https'),
7092
HTTPS_PORT = 3001;
7193

72-
var options = {
94+
const options = {
7395
key: fs.readFileSync(__dirname + '/keys/localhost.pem'),
7496
cert: fs.readFileSync(__dirname + '/keys/localhost.cert')
7597
};

examples/static/index.html

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
<body>
1010
<div class="container">
1111
<h1>IBM Watson Speech JavaScript SDK Examples</h1>
12+
<p>The <a href="https://www.npmjs.com/package/watson-speech">watson-speech</a> library allows you to easily add voice
13+
recognition and synthesis to any web app with minimal code.</p>
14+
<p>Complete source code for these examples is
15+
<a href="https://github.com/watson-developer-cloud/speech-javascript-sdk/tree/master/examples/">available on GitHub</a>.</p>
1216
<h2>Speech to Text</h2>
1317
<h3>Microphone Input</h3>
1418
<ul>
@@ -19,8 +23,8 @@ <h3>Microphone Input</h3>
1923
<li><a href="microphone-streaming-text-to-console.html">Transcribe from Microphone, send text to console</a></li>
2024
<li><a href="microphone-streaming-model.html">Transcribe from Microphone, Streaming with chosen model</a></li>
2125
<li><a href="microphone-streaming-object-to-console.html">Transcribe from Microphone, send JSON to console (includes text and metadata; v0.22+ format)</a></li>
22-
<li><a href="browserify.html">Example bundled with browserify</a>*</li>
23-
<li><a href="webpack.html">Example bundled with Webpack</a>*</li>
26+
<li><a href="browserify.html">Browserify example</a></li>
27+
<li><a href="webpack.html">Webpack example</a></li>
2428
<li><strike><a href="microphone-streaming-object-extracted-to-console.html">Deprecated: Transcribe from Microphone, send JSON to console with results extracted (pre-v0.22 format)</a></strike></li>
2529
</ul>
2630
<h3>File Input</h3>
@@ -34,11 +38,9 @@ <h3>File Input</h3>
3438
<li><a href="realtime-vs-no-realtime.html">Compare <code>realtime</code> and <code>TimingStream</code> options</a></li>
3539
<li><a href="url-promise.html">Transcribe from URL, return a Promise</a></li>
3640
<li><a href="file-ajax.html">Transcribe from file, pre-loaded over AJAX</a></li>
37-
<li><strike><a href="audio-video-deprecated/">Deprecated: Transcribe from HTML5 &lt;audio&gt; or &lt;video&gt; element</a></strike>*</li>
41+
<li><strike><a href="audio-video-deprecated/">Deprecated: Transcribe from HTML5 &lt;audio&gt; or &lt;video&gt; element</a></strike></li>
3842
</ul>
3943

40-
<p>* Examples that depend on browserify or webpack require Node.js and will not work with the example Python server.</p>
41-
4244
<h2>Text to Speech</h2>
4345
<ul>
4446
<li><a href="text-to-speech.html">Synthesize text, with pre-loaded token (compatible with Mobile Safari)</a></li>
@@ -51,6 +53,8 @@ <h2>See Also</h2>
5153
<li><a href="http://watson-developer-cloud.github.io/speech-javascript-sdk/">JSDoc</a></li>
5254
<li><a href="https://www.npmjs.com/package/watson-speech">npm</a></li>
5355
<li><a href="https://github.com/watson-developer-cloud/speech-javascript-sdk">GitHub</a></li>
56+
<li><a href="https://speech-to-text-demo.mybluemix.net/">Official Speech to Text demo</a></li>
57+
<li><a href="https://text-to-speech-demo.mybluemix.net/">Official Text to Speech demo</a></li>
5458
<li><a href="https://www.ibm.com/watson/developercloud/">Watson</a></li>
5559
</ul>
5660
</div>

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"author": "Nathan Friedly <http://nfriedly.com>",
2121
"devDependencies": {
22-
"browserify": "^13.3.0",
22+
"browserify": "^14.0.0",
2323
"concat-stream": "^1.6.0",
2424
"envify": "^4.0.0",
2525
"eslint": "^3.13.1",
@@ -55,7 +55,7 @@
5555
"websocket": "^1.0.24",
5656
"whatwg-fetch": "^2.0.1"
5757
},
58-
"homepage": "https://github.com/watson-developer-cloud/speech-javascript-sdk",
58+
"homepage": "http://watson-speech.mybluemix.net/",
5959
"repository": {
6060
"type": "git",
6161
"url": "https://github.com/watson-developer-cloud/speech-javascript-sdk.git"

webpack.config.js

Whitespace-only changes.

0 commit comments

Comments
 (0)