mirror of
https://github.com/karl0ss/homepage.git
synced 2025-04-29 12:03:41 +01:00
fix widgets without mappings
This commit is contained in:
parent
d999bb3f09
commit
ec8700f3e9
@ -20,34 +20,38 @@ export default async function handler(req, res) {
|
|||||||
|
|
||||||
if (serviceProxyHandler instanceof Function) {
|
if (serviceProxyHandler instanceof Function) {
|
||||||
// map opaque endpoints to their actual endpoint
|
// map opaque endpoints to their actual endpoint
|
||||||
const mapping = widget?.mappings?.[req.query.endpoint];
|
if (widget?.mappings) {
|
||||||
const mappingParams = mapping.params;
|
const mapping = widget?.mappings?.[req.query.endpoint];
|
||||||
const map = mapping?.map;
|
const mappingParams = mapping.params;
|
||||||
const endpoint = mapping?.endpoint;
|
const map = mapping?.map;
|
||||||
const endpointProxy = mapping?.proxyHandler || serviceProxyHandler;
|
const endpoint = mapping?.endpoint;
|
||||||
req.method = mapping?.method || "GET";
|
const endpointProxy = mapping?.proxyHandler || serviceProxyHandler;
|
||||||
|
req.method = mapping?.method || "GET";
|
||||||
|
|
||||||
if (!endpoint) {
|
if (!endpoint) {
|
||||||
logger.debug("Unsupported service endpoint: %s", type);
|
logger.debug("Unsupported service endpoint: %s", type);
|
||||||
return res.status(403).json({ error: "Unsupported service endpoint" });
|
return res.status(403).json({ error: "Unsupported service endpoint" });
|
||||||
|
}
|
||||||
|
|
||||||
|
req.query.endpoint = endpoint;
|
||||||
|
if (req.query.segments) {
|
||||||
|
const segments = JSON.parse(req.query.segments);
|
||||||
|
req.query.endpoint = formatApiCall(endpoint, segments);
|
||||||
|
}
|
||||||
|
if (req.query.query) {
|
||||||
|
const queryParams = JSON.parse(req.query.query);
|
||||||
|
const query = new URLSearchParams(mappingParams.map((p) => [p, queryParams[p]]));
|
||||||
|
req.query.endpoint = `${req.query.endpoint}?${query}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endpointProxy instanceof Function) {
|
||||||
|
return endpointProxy(req, res, map);
|
||||||
|
}
|
||||||
|
|
||||||
|
return serviceProxyHandler(req, res, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
req.query.endpoint = endpoint;
|
return serviceProxyHandler(req, res);
|
||||||
if (req.query.segments) {
|
|
||||||
const segments = JSON.parse(req.query.segments);
|
|
||||||
req.query.endpoint = formatApiCall(endpoint, segments);
|
|
||||||
}
|
|
||||||
if (req.query.query) {
|
|
||||||
const queryParams = JSON.parse(req.query.query);
|
|
||||||
const query = new URLSearchParams(mappingParams.map((p) => [p, queryParams[p]]));
|
|
||||||
req.query.endpoint = `${req.query.endpoint}?${query}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (endpointProxy instanceof Function) {
|
|
||||||
return endpointProxy(req, res, map);
|
|
||||||
}
|
|
||||||
|
|
||||||
return serviceProxyHandler(req, res, map);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("Unknown proxy service type: %s", type);
|
logger.debug("Unknown proxy service type: %s", type);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user