feat: add MAC based POST and GET endpoints

This commit is contained in:
2026-01-27 19:59:28 +01:00
parent dca830b21d
commit eecfbb015d
5 changed files with 1104 additions and 0 deletions

42
api.js Normal file
View File

@@ -0,0 +1,42 @@
import express from 'express';
import cors from 'cors';
import { sendWolPacket } from './wol.js';
const app = express();
const port = 9999;
app.use(cors()).use(express.json());
app.post('/wake', (req, res) => {
const { mac } = req.body;
if(!mac) {
return res.status(400).json({ status: 'error', message: 'MAC address required' });
}
sendWolPacket(mac)
.then(() => res.json({ status: "ok" }))
.catch(err => {
console.error(err);
res.status(500).json({ status: "error", message: "Failed to send WOL packet" })
});
});
app.get('/wake', (req, res) => {
const mac = req.query.mac;
if(!mac) {
return res.status(400).json({ status: 'error', message: 'MAC address required' });
}
sendWolPacket(mac)
.then(() => res.json({ status: "ok" }))
.catch(err => {
console.error(err);
res.status(500).json({ status: "error", message: "Failed to send WOL packet" });
});
});
app.listen(port, () => {
console.log('WOL server running on port ' + port);
});