mirror of
https://github.com/karl0ss/homepage.git
synced 2025-04-29 12:03:41 +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) {
|
||||
let loginUrl = `${widget.url}/api`;
|
||||
if (widget.prefix === udmpPrefix) {
|
||||
loginUrl += "/auth"
|
||||
}
|
||||
loginUrl += "/login";
|
||||
|
||||
const endpoint = (widget.prefix === udmpPrefix) ? "auth/login" : "login";
|
||||
const api = widgets?.[widget.type]?.api?.replace("{prefix}", ""); // no prefix for login url
|
||||
const loginUrl = new URL(formatApiCall(api, { endpoint, ...widget }));
|
||||
const loginBody = { username: widget.username, password: widget.password, remember: true };
|
||||
const headers = { "Content-Type": "application/json" };
|
||||
const [status, contentType, data, responseHeaders] = await httpProxy(loginUrl, {
|
||||
@ -85,6 +82,13 @@ export default async function unifiProxyHandler(req, res) {
|
||||
|
||||
widget.prefix = prefix;
|
||||
|
||||
if (!widget.port) {
|
||||
widget.port = 8443;
|
||||
if (widget.prefix == udmpPrefix) {
|
||||
widget.port = 443
|
||||
}
|
||||
}
|
||||
|
||||
const { endpoint } = req.query;
|
||||
const url = new URL(formatApiCall(api, { endpoint, ...widget }));
|
||||
const params = { method: "GET", headers: {} };
|
||||
|
@ -1,7 +1,7 @@
|
||||
import unifiProxyHandler from "./proxy";
|
||||
|
||||
const widget = {
|
||||
api: "{url}{prefix}/api/{endpoint}",
|
||||
api: "{url}:{port}{prefix}/api/{endpoint}",
|
||||
proxyHandler: unifiProxyHandler,
|
||||
|
||||
mappings: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user