mirror of
https://github.com/gethomepage/homepage.git
synced 2026-01-15 22:02:12 +08:00
Use proxy for cached fetch
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import cache from "memory-cache";
|
import cache from "memory-cache";
|
||||||
|
import { httpProxy } from "utils/proxy/http";
|
||||||
|
|
||||||
const defaultDuration = 5;
|
const defaultDuration = 5;
|
||||||
|
|
||||||
@@ -12,14 +13,13 @@ export default async function cachedFetch(url, duration, ua) {
|
|||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
// wrapping text in JSON.parse to handle utf-8 issues
|
|
||||||
const options = {};
|
const options = {};
|
||||||
if (ua) {
|
if (ua) {
|
||||||
options.headers = {
|
options.headers = {
|
||||||
"User-Agent": ua,
|
"User-Agent": ua,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const data = await fetch(url, options).then((res) => res.json());
|
const [, , data] = await httpProxy(url, options);
|
||||||
cache.put(url, data, duration * 1000 * 60);
|
cache.put(url, data, duration * 1000 * 60);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user