Skip to content

Commit 905db68

Browse files
author
Florian Treml
committed
Read base url from env
1 parent 118a697 commit 905db68

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

frontend/resources/.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ DEBUG=botium*
44
# Comma-separated list of API Tokens to allow. If empty, API Tokens are not required.
55
BOTIUM_API_TOKENS=
66

7+
# Server URL as seen by clients
8+
#BOTIUM_SPEECH_URL=https://speech.botiumbox.com
9+
710
# Maximum file size for STT
811
BOTIUM_SPEECH_UPLOAD_LIMIT=50mb
912

frontend/src/routes.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const sanitize = require('sanitize-filename')
1010
const contentDisposition = require('content-disposition')
1111
const { WebSocketServer } = require('ws')
1212
const { runconvert } = require('./convert/convert')
13-
const { wer } = require('./utils')
13+
const { wer, readBaseUrls } = require('./utils')
1414
const debug = require('debug')('botium-speech-processing-routes')
1515

1616
const cachePathStt = (process.env.BOTIUM_SPEECH_CACHE_DIR && path.join(process.env.BOTIUM_SPEECH_CACHE_DIR, 'stt')) || './resources/.cache/stt'
@@ -714,14 +714,11 @@ const wssStreams = {}
714714
stream.events.on('close', () => delete wssStreams[streamId])
715715
wssStreams[streamId] = stream
716716

717-
const proxyHost = req.headers['x-forwarded-host']
718-
const host = proxyHost || req.get('host')
719-
720-
const wsProtocol = (req.protocol === 'https' ? 'wss' : 'ws')
717+
const baseUrls = readBaseUrls(req)
721718
res.json({
722-
wsUri: `${wsProtocol}://${host}/${streamId}`,
723-
statusUri: `${req.protocol}://${host}/api/sttstatus/${streamId}`,
724-
endUri: `${req.protocol}://${host}/api/sttend/${streamId}`
719+
wsUri: `${baseUrls.wsUri}/${streamId}`,
720+
statusUri: `${baseUrls.baseUri}/api/sttstatus/${streamId}`,
721+
endUri: `${baseUrls.baseUri}/api/sttend/${streamId}`
725722
}).end()
726723
} catch (err) {
727724
return next(err)

frontend/src/utils.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,22 @@ const ibmTtsOptions = (req) => {
7474
throw new Error('IBM Cloud credentials not found')
7575
}
7676

77+
const readBaseUrls = (req) => {
78+
const proto = process.env.BOTIUM_SPEECH_URL ? process.env.BOTIUM_SPEECH_URL.split('://')[0] : req.protocol
79+
const host = process.env.BOTIUM_SPEECH_URL ? process.env.BOTIUM_SPEECH_URL.split('://')[1] : req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'] : req.get('host')
80+
81+
return {
82+
wsUri: `${proto === 'https' ? 'wss' : 'ws'}://${host}`,
83+
baseUri: `${proto}://${host}`
84+
}
85+
}
86+
7787
module.exports = {
7888
asJson,
7989
wer,
8090
ttsFilename,
8191
googleOptions,
8292
ibmSttOptions,
83-
ibmTtsOptions
93+
ibmTtsOptions,
94+
readBaseUrls
8495
}

0 commit comments

Comments
 (0)