mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-07 14:18:47 +00:00
Add AdGuard, Bazarr, and Coin Market Cap widgets
- Allow setting HTTP method in widget.js - Allow sending allow listed query params to proxy
This commit is contained in:
parent
f999f4a467
commit
03fa2f86d7
10 changed files with 251 additions and 9 deletions
|
@ -1,3 +1,5 @@
|
|||
import { URLSearchParams } from "next/dist/compiled/@edge-runtime/primitives/url";
|
||||
|
||||
import createLogger from "utils/logger";
|
||||
import genericProxyHandler from "utils/proxies/generic";
|
||||
import widgets from "widgets/widgets";
|
||||
|
@ -15,20 +17,30 @@ export default async function handler(req, res) {
|
|||
}
|
||||
|
||||
const serviceProxyHandler = widget.proxyHandler || genericProxyHandler;
|
||||
req.method = "GET";
|
||||
|
||||
if (serviceProxyHandler instanceof Function) {
|
||||
// map opaque endpoints to their actual endpoint
|
||||
const mapping = widget?.mappings?.[req.query.endpoint];
|
||||
const mappingParams = mapping.params;
|
||||
const map = mapping?.map;
|
||||
const endpoint = mapping?.endpoint;
|
||||
const endpointProxy = mapping?.proxyHandler;
|
||||
const endpointProxy = mapping?.proxyHandler || serviceProxyHandler;
|
||||
req.method = mapping?.method || "GET";
|
||||
|
||||
if (!endpoint) {
|
||||
logger.debug("Unsupported service endpoint: %s", type);
|
||||
return res.status(403).json({ error: "Unsupported service endpoint" });
|
||||
}
|
||||
|
||||
req.query.endpoint = endpoint;
|
||||
if (req.query.params) {
|
||||
const queryParams = JSON.parse(req.query.params);
|
||||
const query = new URLSearchParams(mappingParams.map(p => [p, queryParams[p]]));
|
||||
req.query.endpoint = `${endpoint}?${query}`;
|
||||
}
|
||||
else {
|
||||
req.query.endpoint = endpoint;
|
||||
}
|
||||
|
||||
if (endpointProxy instanceof Function) {
|
||||
return endpointProxy(req, res, map);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue