Add server-side logging and timeout option (#366)

This commit is contained in:
Max Lee 2025-06-04 15:07:00 +01:00 committed by GitHub
commit 8b2276a7ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,9 +16,23 @@ try {
const app = express()
const isProd = process.argv.includes('--prod') || process.env.NODE_ENV === 'production'
const timeoutIndex = process.argv.indexOf('--timeout')
let timeout = timeoutIndex > -1 && timeoutIndex + 1 < process.argv.length
? parseInt(process.argv[timeoutIndex + 1])
: process.env.TIMEOUT
? parseInt(process.env.TIMEOUT)
: 10000
if (isNaN(timeout) || timeout < 0) {
console.warn('Invalid timeout value provided, using default of 10000ms')
timeout = 10000
}
app.use(compression())
app.use(cors())
app.use(netApi({ allowOrigin: '*' }))
app.use(netApi({
allowOrigin: '*',
log: process.argv.includes('--log') || process.env.LOG === 'true',
timeout
}))
if (!isProd) {
app.use('/sounds', express.static(path.join(__dirname, './generated/sounds/')))
}