feat: add web page with buttons to wake up targets, add /targets endpoint to get all available targets in JSON format

This commit is contained in:
2026-01-28 02:56:15 +01:00
parent c917fd739a
commit 95d0e3eb74

31
api.js
View File

@@ -8,7 +8,30 @@ const port = 9999;
app.use(cors()).use(express.json());
app.post('/wake', (req, res) => {
app.get("/", (req, res) => {
let html = `<!DOCTYPE html><head>
<style>
body { background: #fff; color: #000; }
@media (prefers-color-scheme: dark) {
body { background: #111; color: #eee; }
a { color: #7295f6; }
}
</style>
</head>
<body>
<h2 style="margin-bottom: 5px">Targets:</h2>
<ul style="margin: 0; padding-left: 0; list-style-position: inside">
${Object.keys(targets).map(key => `<li><a href="/wake/${key}">${key}</a></li>`).join("")}
</ul>
</body>`;
res.send(html);
});
app.get("/targets", (req, res) => {
res.json(Object.keys(targets));
});
app.post("/wake", (req, res) => {
const { mac } = req.body;
if(!mac) {
@@ -23,7 +46,7 @@ app.post('/wake', (req, res) => {
});
});
app.get('/wake', (req, res) => {
app.get("/wake", (req, res) => {
const mac = req.query.mac;
if(!mac) {
@@ -54,10 +77,6 @@ app.get("/wake/:name", (req, res) => {
});
});
app.get("/targets", (req, res) => {
res.json(Object.keys(targets));
});
app.listen(port, () => {
console.log('WOL server running on port ' + port);
});