-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
51 lines (38 loc) · 1009 Bytes
/
server.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
const express = require('express')
const app = express()
const Robot = require('./lib/robot')
const nodebot = Robot({
mlPositive: 22,
mlNegative: 23,
mrPositive: 24,
mrNegative: 25
})
const takePicture = require('./lib/take-picture')
const done = action => () => console.log('Robot : ', action)
app.use(express.static('public'))
app.post('/robot/left', (req, res) => {
nodebot.moveLeft().then(done('left'))
res.end('ok')
})
app.post('/robot/right', (req, res) => {
nodebot.moveRight().then(done('right'))
res.end('ok')
})
app.post('/robot/forward', (req, res) => {
nodebot.moveForward().then(done('right'))
res.end('ok')
})
app.post('/robot/backward', (req, res) => {
nodebot.moveBackward().then(done('backward'))
res.end('ok')
})
app.post('/robot/stop', (req, res) => {
nodebot.stop().then(done
('stop'))
res.end('ok')
})
app.post('/robot/picture', (req, res) => {
takePicture()
res.end('ok')
})
app.listen(3000, () => console.log('Server started on port 3000'))