Skip to content

fix: Update dependencies #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Environment variables
# You need to provide either username and password
SPEECH_TO_TEXT_USERNAME=
SPEECH_TO_TEXT_PASSWORD=
# OR IAM API key and URL
SPEECH_TO_TEXT_IAM_APIKEY=
SPEECH_TO_TEXT_IAM_URL=
# Service URL
SPEECH_TO_TEXT_URL=https://stream.watsonplatform.net/speech-to-text/api
SPEECH_TO_TEXT_URL=https://stream.watsonplatform.net/speech-to-text/api
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: node_js
dist: trusty
sudo: required
node_js: '8'
node_js: 12
script:
- npm run test

Expand All @@ -25,5 +24,3 @@ deploy:
- provider: script
skip_cleanup: true
script: npx semantic-release
on:
node: 8
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

FROM centos:centos6
RUN curl -sL https://rpm.nodesource.com/setup_8.x | bash -
RUN curl -sL https://rpm.nodesource.com/setup_12.x | bash -
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we are modifying this, why not just use the official node images instead of doing this work ourselves? https://hub.docker.com/_/node/

RUN yum install -y nodejs #
# Define working directory.
COPY . /src
Expand Down
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ You can view a [demo][demo_url] of this app.
- Log in to your IBM Cloud account.
- Click **Create**.
- Click **Show** to view the service credentials.
- Copy the `apikey` value, or copy the `username` and `password` values if your service instance doesn't provide an `apikey`.
- Copy the `apikey` value.
- Copy the `url` value.

## Configuring the application
Expand All @@ -43,16 +43,6 @@ You can view a [demo][demo_url] of this app.
SPEECH_TO_TEXT_URL=https://gateway-wdc.watsonplatform.net/speech-to-text/api
```

- If your service instance uses `username` and `password` credentials, add the `SPEECH_TO_TEXT_USERNAME` and `SPEECH_TO_TEXT_PASSWORD` variables to the *.env* file.

Example *.env* file that configures the `username`, `password`, and `url` for a Speech to Text service instance hosted in the Sydney region:

```
SPEECH_TO_TEXT_USERNAME=522be-7b41-ab44-dec3-g1eab2ha73c6
SPEECH_TO_TEXT_PASSWORD=A4Z5BdGENrwu8
SPEECH_TO_TEXT_URL=https://gateway-syd.watsonplatform.net/speech-to-text/api
```

## Running locally

1. Install the dependencies
Expand Down Expand Up @@ -105,7 +95,7 @@ You can view a [demo][demo_url] of this app.
Find more open source projects on the [IBM Github Page](http://ibm.github.io/)


[service_url]: https://www.ibm.com/watson/services/speech-to-text/
[service_url]: https://www.ibm.com/cloud/watson-speech-to-text
[docs]: https://cloud.ibm.com/apidocs/speech-to-text
[sign_up]: https://cloud.ibm.com/registration/?target=/catalog/services/speech-to-text/
[demo_url]: https://speech-to-text-demo.ng.bluemix.net
58 changes: 16 additions & 42 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,57 +17,31 @@
const express = require('express');

const app = express();
const SpeechToTextV1 = require('ibm-watson/speech-to-text/v1');
const AuthorizationV1 = require('ibm-watson/authorization/v1');
const IamTokenManagerV1 = require('ibm-watson/iam-token-manager/v1');
const { IamTokenManager } = require('ibm-watson/auth');

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

// Create the token manager
let tokenManager;
let instanceType;
const serviceUrl = process.env.SPEECH_TO_TEXT_URL || 'https://stream.watsonplatform.net/speech-to-text/api';
const serviceUrl = process.env.SPEECH_TO_TEXT_URL;

const tokenManager = new IamTokenManager({
apikey: process.env.SPEECH_TO_TEXT_IAM_APIKEY || '<iam_apikey>',
});

if (process.env.SPEECH_TO_TEXT_IAM_APIKEY && process.env.SPEECH_TO_TEXT_IAM_APIKEY !== '') {
instanceType = 'iam';
tokenManager = new IamTokenManagerV1({
iamApikey: process.env.SPEECH_TO_TEXT_IAM_APIKEY || '<iam_apikey>',
iamUrl: process.env.SPEECH_TO_TEXT_IAM_URL || 'https://iam.bluemix.net/identity/token',
});
} else {
instanceType = 'cf';
const speechService = new SpeechToTextV1({
username: process.env.SPEECH_TO_TEXT_USERNAME || '<username>',
password: process.env.SPEECH_TO_TEXT_PASSWORD || '<password>',
url: serviceUrl,
});
tokenManager = new AuthorizationV1(speechService.getServiceCredentials());
}

app.get('/', (req, res) => res.render('index'));

// Get credentials using your credentials
app.get('/api/v1/credentials', (req, res, next) => {
tokenManager.getToken((err, token) => {
if (err) {
next(err);
} else {
let credentials;
if (instanceType === 'iam') {
credentials = {
accessToken: token,
serviceUrl,
};
} else {
credentials = {
token: token.token,
serviceUrl,
};
}
res.json(credentials);
}
});
app.get('/api/v1/credentials', async (req, res, next) => {
try {
const accessToken = await tokenManager.getToken();
res.json({
accessToken,
serviceUrl,
});
} catch (err) {
next(err);
}
});

module.exports = app;
4 changes: 2 additions & 2 deletions casper-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
require('dotenv').config({ silent: true });

if (!process.env.SPEECH_TO_TEXT_IAM_APIKEY && !process.env.SPEECH_TO_TEXT_USERNAME) {
if (!process.env.SPEECH_TO_TEXT_IAM_APIKEY) {
console.log(
'Skipping integration tests because SPEECH_TO_TEXT_IAM_APIKEY and SPEECH_TO_TEXT_USERNAME are null',
'Skipping integration tests because SPEECH_TO_TEXT_IAM_APIKEY is null',
);
process.exit(0);
}
Expand Down
6 changes: 0 additions & 6 deletions manifest.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
---
declared-services:
my-stt-service:
label: speech_to_text
plan: standard
applications:
- name: speech-to-text-demo
path: .
command: npm start
memory: 512M
services:
- my-stt-service
Loading