Compare commits
2 Commits
c917fd739a
...
67daf00f04
| Author | SHA1 | Date | |
|---|---|---|---|
| 67daf00f04 | |||
| 95d0e3eb74 |
@@ -11,6 +11,10 @@ Wake-on-LAN API in Node.js
|
|||||||
2. Edit the file and add your targets
|
2. Edit the file and add your targets
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
Navigate to `http://localhost:9999` and just click the target you want to wake up.
|
||||||
|
|
||||||
|
Or:
|
||||||
|
|
||||||
### POST to `/wake`
|
### POST to `/wake`
|
||||||
```bash
|
```bash
|
||||||
curl -X POST -H "Content-Type: application/json" -d '{
|
curl -X POST -H "Content-Type: application/json" -d '{
|
||||||
@@ -23,6 +27,11 @@ curl -X POST -H "Content-Type: application/json" -d '{
|
|||||||
curl http://localhost:9999/wake?mac=00:AA:BB:CC:DD:EE
|
curl http://localhost:9999/wake?mac=00:AA:BB:CC:DD:EE
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### GET to `/targets`
|
||||||
|
```bash
|
||||||
|
curl http://localhost:9999/targets
|
||||||
|
```
|
||||||
|
|
||||||
### GET to `/wake/:name`
|
### GET to `/wake/:name`
|
||||||
```bash
|
```bash
|
||||||
curl http://localhost:9999/wake/<target name>
|
curl http://localhost:9999/wake/<target name>
|
||||||
|
|||||||
31
api.js
31
api.js
@@ -8,7 +8,30 @@ const port = 9999;
|
|||||||
|
|
||||||
app.use(cors()).use(express.json());
|
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;
|
const { mac } = req.body;
|
||||||
|
|
||||||
if(!mac) {
|
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;
|
const mac = req.query.mac;
|
||||||
|
|
||||||
if(!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, () => {
|
app.listen(port, () => {
|
||||||
console.log('WOL server running on port ' + port);
|
console.log('WOL server running on port ' + port);
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user