fetch data from media server api

This commit is contained in:
srgooglo 2022-05-12 10:53:15 +02:00
parent 0ae6cbc0d9
commit bb2cd23c4b

View File

@ -4,7 +4,10 @@ import { nanoid } from "nanoid"
import axios from "axios" import axios from "axios"
const streamingServerAddress = "media.ragestudio.net" const streamingServerAddress = process.env.mediaServerAddress ?? "media.ragestudio.net"
const streamingServerAPIPort = process.env.mediaServerAPIPort ?? 3002
const streamingServerAPIProtocol = process.env.mediaServerAPIProtocol ?? "http"
const streamingServerAPIUri = `${streamingServerAPIProtocol}://${streamingServerAddress}:${streamingServerAPIPort}`
export default class StreamingController extends Controller { export default class StreamingController extends Controller {
static useMiddlewares = ["withAuthentication"] static useMiddlewares = ["withAuthentication"]
@ -28,15 +31,15 @@ export default class StreamingController extends Controller {
get = { get = {
"/streams": async (req, res) => { "/streams": async (req, res) => {
// TODO: meanwhile linebridge remote linkers are in development we gonna use this methods to fetch // TODO: meanwhile linebridge remote linkers are in development we gonna use this methods to fetch
const result = await axios.get(`http://${streamingServerAddress}/streams`).catch((error) => { const { data } = await axios.get(`${streamingServerAPIUri}/streams`).catch((error) => {
res.status(500).json({ res.status(500).json({
error: `Failed to fetch streams from [${streamingServerAddress}]: ${error.message}` error: `Failed to fetch streams from [${streamingServerAddress}]: ${error.message}`
}) })
return false return false
}) })
if (result) { if (data) {
console.log(result) return res.json(data)
} }
}, },
"/target_streaming_server": async (req, res) => { "/target_streaming_server": async (req, res) => {
@ -73,6 +76,4 @@ export default class StreamingController extends Controller {
} }
}, },
} }
} }