This repository has been archived by the owner on Jul 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (54 loc) · 1.36 KB
/
index.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Global Dir Hack
global.baseDir = `${__dirname}/`
// Load Config settings
const dir = require(`${global.baseDir}directories`)
const wemoClient = require(`${dir.services}wemoClient`)
const setupServer = require(`${dir.server}setupServer`)
const startServer = require(`${dir.server}startServer`)
// Load Middleware
const toggleDevices = require(`${dir.middleware}toggleDevices`)
const turnOffDevices = require(`${dir.middleware}turnOffDevices`)
const turnOnDevices = require(`${dir.middleware}turnOnDevices`)
wemoClient.init()
const serverSettings = setupServer()
serverSettings.get(
'/',
(req, res) => res.end('You no be hearz.')
)
serverSettings.get(
'/toggle-device/:name',
(req, res) => res.send(
toggleDevices(wemoClient)([req.params.name])
)
)
serverSettings.put(
'/toggle-device',
(req, res) => res.send(
toggleDevices(wemoClient)(req.body.names)
)
)
serverSettings.get(
'/turn-off-device/:name',
(req, res) => res.send(
turnOffDevices(wemoClient)([req.params.name])
)
)
serverSettings.put(
'/turn-off-device',
(req, res) => res.send(
turnOffDevices(wemoClient)(req.body.names)
)
)
serverSettings.get(
'/turn-on-device/:name',
(req, res) => res.send(
turnOnDevices(wemoClient)([req.params.name])
)
)
serverSettings.put(
'/turn-on-device',
(req, res) => res.send(
turnOnDevices(wemoClient)(req.body.names)
)
)
startServer(serverSettings)