|
|
@ -24,6 +24,7 @@ export default async function xteveProxyHandler(req, res) {
|
|
|
|
const payload = { cmd: "status" };
|
|
|
|
const payload = { cmd: "status" };
|
|
|
|
|
|
|
|
|
|
|
|
if (widget.username && widget.password) {
|
|
|
|
if (widget.username && widget.password) {
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
const [status, contentType, data] = await httpProxy(url, {
|
|
|
|
const [status, contentType, data] = await httpProxy(url, {
|
|
|
|
method,
|
|
|
|
method,
|
|
|
|
body: JSON.stringify({
|
|
|
|
body: JSON.stringify({
|
|
|
@ -34,14 +35,14 @@ export default async function xteveProxyHandler(req, res) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (status !== 200) {
|
|
|
|
if (status !== 200) {
|
|
|
|
return [status, contentType, data];
|
|
|
|
logger.debug("Error logging into xteve", status, url);
|
|
|
|
|
|
|
|
return res.status(status).json({error: {message: `HTTP Error ${status} logging into xteve`, url, data}});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const json = JSON.parse(data.toString());
|
|
|
|
const json = JSON.parse(data.toString());
|
|
|
|
|
|
|
|
|
|
|
|
if (json?.status !== true) {
|
|
|
|
if (json?.status !== true) {
|
|
|
|
const message = "Authentication failed.";
|
|
|
|
return res.status(401).json({error: {message: "Authentication failed", url, data}});
|
|
|
|
return res.status(401).end(JSON.stringify({error: { message } }));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
payload.token = json.token;
|
|
|
|
payload.token = json.token;
|
|
|
@ -53,8 +54,8 @@ export default async function xteveProxyHandler(req, res) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (status !== 200) {
|
|
|
|
if (status !== 200) {
|
|
|
|
logger.debug("Error %d calling endpoint %s", status, url);
|
|
|
|
logger.debug("Error %d calling xteve endpoint %s", status, url);
|
|
|
|
return res.status(status, data);
|
|
|
|
return res.status(status).json({error: {message: `HTTP Error ${status}`, url, data}});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (contentType) res.setHeader("Content-Type", contentType);
|
|
|
|
if (contentType) res.setHeader("Content-Type", contentType);
|
|
|
|