Display TpLink Tapo power usage values
This commit is contained in:
parent
e6b5fed399
commit
a0487c0b59
5 changed files with 187 additions and 0 deletions
18
app/api/power/route.ts
Normal file
18
app/api/power/route.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const token = req.cookies.get("token")?.value;
|
||||
if (!token) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
const res = await fetch("http://localhost:3001/power", {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
return NextResponse.json({ error: "Upstream error" }, { status: res.status });
|
||||
}
|
||||
|
||||
return NextResponse.json(await res.json());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue