Last active
April 21, 2020 12:11
-
-
Save artoliukkonen/7a17a1b9c0c487505f3effe1339f4b9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cors = require('cors') | |
var fs = require('fs') | |
var bodyParser = require('body-parser') | |
var express = require('express'), | |
app = express(), | |
port = process.env.PORT || 8080; | |
app.use(cors()) | |
app.use(bodyParser.json()); | |
app.listen(port) | |
app.put('/brightness', async (req, res) => { | |
const { device, brightness } = req.body; | |
const light = devices[device].lightList[0]; | |
light.setBrightness(brightness, 2); | |
res.send('ok'); | |
}); | |
app.put('/toggle', async (req, res) => { | |
const { device } = req.body; | |
const light = devices[device].lightList ? devices[device].lightList[0] : devices[device].plugList[0]; | |
light.toggle(); | |
res.send('ok'); | |
}); | |
app.put('/on', async (req, res) => { | |
const { device } = req.body; | |
const light = devices[device].lightList ? devices[device].lightList[0] : devices[device].plugList[0]; | |
light.turnOn(); | |
res.send('ok'); | |
}); | |
app.put('/off', async (req, res) => { | |
const { device } = req.body; | |
const light = devices[device].lightList ? devices[device].lightList[0] : devices[device].plugList[0]; | |
light.turnOff(); | |
res.send('ok'); | |
}); | |
app.get('/list', async (req, res) => { | |
res.send({ lightbulbs: { ...lightbulbs }, plugs: { ...plugs } }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment