mirror of
https://github.com/karl0ss/homepage.git
synced 2025-05-01 21:13:39 +01:00
Infer unifi port, use api widget property for login
This commit is contained in:
parent
fe1064b173
commit
d1b6dad14d
@ -43,12 +43,9 @@ async function getWidget(req) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function login(widget) {
|
async function login(widget) {
|
||||||
let loginUrl = `${widget.url}/api`;
|
const endpoint = (widget.prefix === udmpPrefix) ? "auth/login" : "login";
|
||||||
if (widget.prefix === udmpPrefix) {
|
const api = widgets?.[widget.type]?.api?.replace("{prefix}", ""); // no prefix for login url
|
||||||
loginUrl += "/auth"
|
const loginUrl = new URL(formatApiCall(api, { endpoint, ...widget }));
|
||||||
}
|
|
||||||
loginUrl += "/login";
|
|
||||||
|
|
||||||
const loginBody = { username: widget.username, password: widget.password, remember: true };
|
const loginBody = { username: widget.username, password: widget.password, remember: true };
|
||||||
const headers = { "Content-Type": "application/json" };
|
const headers = { "Content-Type": "application/json" };
|
||||||
const [status, contentType, data, responseHeaders] = await httpProxy(loginUrl, {
|
const [status, contentType, data, responseHeaders] = await httpProxy(loginUrl, {
|
||||||
@ -85,6 +82,13 @@ export default async function unifiProxyHandler(req, res) {
|
|||||||
|
|
||||||
widget.prefix = prefix;
|
widget.prefix = prefix;
|
||||||
|
|
||||||
|
if (!widget.port) {
|
||||||
|
widget.port = 8443;
|
||||||
|
if (widget.prefix == udmpPrefix) {
|
||||||
|
widget.port = 443
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const { endpoint } = req.query;
|
const { endpoint } = req.query;
|
||||||
const url = new URL(formatApiCall(api, { endpoint, ...widget }));
|
const url = new URL(formatApiCall(api, { endpoint, ...widget }));
|
||||||
const params = { method: "GET", headers: {} };
|
const params = { method: "GET", headers: {} };
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import unifiProxyHandler from "./proxy";
|
import unifiProxyHandler from "./proxy";
|
||||||
|
|
||||||
const widget = {
|
const widget = {
|
||||||
api: "{url}{prefix}/api/{endpoint}",
|
api: "{url}:{port}{prefix}/api/{endpoint}",
|
||||||
proxyHandler: unifiProxyHandler,
|
proxyHandler: unifiProxyHandler,
|
||||||
|
|
||||||
mappings: {
|
mappings: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user