-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
51 lines (41 loc) · 1.41 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var express = require("express");
var path = require("path");
var cookieParser = require("cookie-parser");
var logger = require("morgan");
var bodyParser = require("body-parser");
const { IamTokenManager } = require("ibm-watson/auth");
// allows environment properties to be set in a file named .env
require("dotenv").config({ silent: true });
if (!process.env.SPEECH_TO_TEXT_IAM_APIKEY) {
console.error(
"Missing required credentials - see https://github.com/watson-developer-cloud/node-sdk#getting-the-service-credentials"
);
process.exit(1);
}
var indexRouter = require("./src/backend/routes/index");
var app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json({ limit: "10mb" }));
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "dist")));
app.use(express.static(path.join(__dirname, "public")));
app.use("/", indexRouter);
const sttAuthenticator = new IamTokenManager({
apikey: process.env.SPEECH_TO_TEXT_IAM_APIKEY,
});
// speech to text token endpoint
app.use("/api/speech-to-text/token", function (req, res) {
return sttAuthenticator
.requestToken()
.then(({ result }) => {
res.json({
accessToken: result.access_token,
url: process.env.SPEECH_TO_TEXT_URL,
});
})
.catch(console.error);
});
module.exports = app;