-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpvcache.mjs
More file actions
25 lines (24 loc) · 798 Bytes
/
Copy pathpvcache.mjs
File metadata and controls
25 lines (24 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { createServer } from "http";
const fallBack = JSON.stringify({ Body: { Data: { Site: { P_PV: null } } } });
const server = createServer(async function (_, res) {
console.log(`request`);
try {
const realtime = await fetch(
"http://pv.fritz.box/solar_api/v1/GetPowerFlowRealtimeData.fcgi"
);
for (const header of realtime.headers.entries()) {
res.setHeader(header[0], header[1]);
}
res.writeHead(200);
res.end(await realtime.text());
} catch {
res.setHeader("content-type", "application/json");
res.setHeader("cache-control", "no-cache, no-store, must-revalidate");
res.setHeader("pragma", "no-cache");
res.writeHead(200);
res.end(fallBack);
}
});
server.listen(8000, "0.0.0.0", () => {
console.log(`Server is running`);
});