Skip to content

Commit

Permalink
Read base url from env
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Treml committed Dec 7, 2021
1 parent 118a697 commit 905db68
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
3 changes: 3 additions & 0 deletions frontend/resources/.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ DEBUG=botium*
# Comma-separated list of API Tokens to allow. If empty, API Tokens are not required.
BOTIUM_API_TOKENS=

# Server URL as seen by clients
#BOTIUM_SPEECH_URL=https://speech.botiumbox.com

# Maximum file size for STT
BOTIUM_SPEECH_UPLOAD_LIMIT=50mb

Expand Down
13 changes: 5 additions & 8 deletions frontend/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const sanitize = require('sanitize-filename')
const contentDisposition = require('content-disposition')
const { WebSocketServer } = require('ws')
const { runconvert } = require('./convert/convert')
const { wer } = require('./utils')
const { wer, readBaseUrls } = require('./utils')
const debug = require('debug')('botium-speech-processing-routes')

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

const proxyHost = req.headers['x-forwarded-host']
const host = proxyHost || req.get('host')

const wsProtocol = (req.protocol === 'https' ? 'wss' : 'ws')
const baseUrls = readBaseUrls(req)
res.json({
wsUri: `${wsProtocol}://${host}/${streamId}`,
statusUri: `${req.protocol}://${host}/api/sttstatus/${streamId}`,
endUri: `${req.protocol}://${host}/api/sttend/${streamId}`
wsUri: `${baseUrls.wsUri}/${streamId}`,
statusUri: `${baseUrls.baseUri}/api/sttstatus/${streamId}`,
endUri: `${baseUrls.baseUri}/api/sttend/${streamId}`
}).end()
} catch (err) {
return next(err)
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,22 @@ const ibmTtsOptions = (req) => {
throw new Error('IBM Cloud credentials not found')
}

const readBaseUrls = (req) => {
const proto = process.env.BOTIUM_SPEECH_URL ? process.env.BOTIUM_SPEECH_URL.split('://')[0] : req.protocol
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')

return {
wsUri: `${proto === 'https' ? 'wss' : 'ws'}://${host}`,
baseUri: `${proto}://${host}`
}
}

module.exports = {
asJson,
wer,
ttsFilename,
googleOptions,
ibmSttOptions,
ibmTtsOptions
ibmTtsOptions,
readBaseUrls
}

0 comments on commit 905db68

Please sign in to comment.