-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (24 loc) · 786 Bytes
/
server.js
File metadata and controls
32 lines (24 loc) · 786 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
26
27
28
29
30
31
32
require("dotenv").config();
const express = require("express");
const bodyParser = require("body-parser");
const { randomizeLights } = require("./lib/helpers");
// enable cron job
require("./lib/cron");
const app = express();
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
const PORT = process.env.PORT || 3000;
app.post("/randomize", async (req, res, next) => {
try {
const { data } = req.body;
await randomizeLights(JSON.parse(data));
res.status(200).send(`Lights have been randomized: ${data}`);
} catch (err) {
res.status(500).send(err.message);
}
});
app.listen(PORT, () => {
console.log(`Hue Server running at http://localhost:${PORT}`);
});