Spaces:
Runtime error
Runtime error
File size: 623 Bytes
e4eeb10 e423758 e4eeb10 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import express from 'express'
const app = express()
const port = 7860
app.use(express.static('public'))
app.get('/stats', async (req, res) => {
try {
const results = await fetch(process.env.WEBTV_MEDIA_SERVER_API_URL)
const json = await results.json()
const response = Object.entries(json.live).reduce((acc, [key, channel]) => ({
...acc,
[key]: (channel as any).subscribers.length
}), {})
res.write(JSON.stringify(response))
res.end()
} catch (err) {
res.write(JSON.stringify({}))
res.end()
}
})
app.listen(port, () => { console.log(`Open http://localhost:${port}`) }) |