Initial commit
This commit is contained in:
122
src/srv/proxy.ts
Normal file
122
src/srv/proxy.ts
Normal file
@@ -0,0 +1,122 @@
|
||||
/* Proxy to bypass CORS (tauon does not pass these headers) */
|
||||
|
||||
import express from "express"
|
||||
import cors from "cors"
|
||||
import compression from "compression"
|
||||
|
||||
const app = express()
|
||||
app.use(cors())
|
||||
app.use(compression())
|
||||
|
||||
app.get("/version", (req, res) => {
|
||||
let host = req.query.host
|
||||
if (typeof host !== "string") {
|
||||
return res.status(400).send("No host")
|
||||
}
|
||||
if (!host.includes(":")) {
|
||||
host = host + ":7814"
|
||||
}
|
||||
fetch(`http://${host}/api1/version`)
|
||||
.then(fetchRes => fetchRes.json())
|
||||
.then(fetchRes => {
|
||||
return res.status(200).send(fetchRes)
|
||||
})
|
||||
.catch((err) => {
|
||||
return res.status(500).send(err)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
app.get("/status", (req, res) => {
|
||||
let host = req.query.host
|
||||
if (typeof host !== "string") {
|
||||
return res.status(400).send("No host")
|
||||
}
|
||||
if (!host.includes(":")) {
|
||||
host = host + ":7814"
|
||||
}
|
||||
fetch(`http://${host}/api1/status`)
|
||||
.then(fetchRes => fetchRes.json())
|
||||
.then(fetchRes => {
|
||||
return res.status(200).send(fetchRes)
|
||||
})
|
||||
.catch((err) => {
|
||||
return res.status(500).send(err)
|
||||
})
|
||||
})
|
||||
|
||||
app.get("/pic", (req, res) => {
|
||||
let host = req.query.host
|
||||
const size = req.query.size
|
||||
const id = req.query.id
|
||||
|
||||
|
||||
if (typeof host !== "string" || !size || !id)
|
||||
return res.status(400).send("Bad parameters")
|
||||
|
||||
if (!host.includes(":")) {
|
||||
host = host + ":7814"
|
||||
}
|
||||
|
||||
fetch(`http://${host}/api1/pic/${size}/${id}`)
|
||||
.then(raw => raw.arrayBuffer())
|
||||
.then(arrBuff => Buffer.from(arrBuff))
|
||||
.then(buff => {
|
||||
return res.send(buff)
|
||||
})
|
||||
})
|
||||
|
||||
app.get("/play", (req, res) => {
|
||||
let host = req.query.host
|
||||
if (typeof host !== "string")
|
||||
return res.status(400).send("Bad host")
|
||||
|
||||
if (!host.includes(":")) {
|
||||
host = host + ":7814"
|
||||
}
|
||||
|
||||
fetch(`http://${host}/api1/play`)
|
||||
return res.status(200).end()
|
||||
})
|
||||
|
||||
app.get("/pause", (req, res) => {
|
||||
let host = req.query.host
|
||||
if (typeof host !== "string")
|
||||
return res.status(400).send("Bad host")
|
||||
|
||||
if (!host.includes(":")) {
|
||||
host = host + ":7814"
|
||||
}
|
||||
|
||||
fetch(`http://${host}/api1/pause`)
|
||||
return res.status(200).end()
|
||||
})
|
||||
|
||||
app.get("/next", (req, res) => {
|
||||
let host = req.query.host
|
||||
if (typeof host !== "string")
|
||||
return res.status(400).send("Bad host")
|
||||
|
||||
if (!host.includes(":")) {
|
||||
host = host + ":7814"
|
||||
}
|
||||
|
||||
fetch(`http://${host}/api1/next`)
|
||||
return res.status(200).end()
|
||||
})
|
||||
|
||||
app.get("/back", (req, res) => {
|
||||
let host = req.query.host
|
||||
if (typeof host !== "string")
|
||||
return res.status(400).send("Bad host")
|
||||
|
||||
if (!host.includes(":")) {
|
||||
host = host + ":7814"
|
||||
}
|
||||
|
||||
fetch(`http://${host}/api1/back`)
|
||||
return res.status(200).end()
|
||||
})
|
||||
|
||||
|
||||
app.listen(7815, () => console.log("MuonRC Proxy listening on 7815"))
|
||||
Reference in New Issue
Block a user