2017-08-22 01:11:07 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const ble = require('./lib/blootstrap')
|
2017-08-22 03:54:38 +00:00
|
|
|
const intval = require('./lib/intval')
|
2017-08-22 01:23:48 +00:00
|
|
|
const restify = require('restify')
|
|
|
|
const logger = require('winston')
|
2017-08-22 02:59:44 +00:00
|
|
|
const fs = require('fs')
|
2017-08-22 01:23:48 +00:00
|
|
|
const pin = {}
|
|
|
|
|
2017-08-22 02:59:44 +00:00
|
|
|
const PACKAGE = require('./package.json')
|
2017-08-22 01:11:07 +00:00
|
|
|
const PORT = process.env.PORT || 6699
|
2017-08-22 02:59:44 +00:00
|
|
|
const APPNAME = PACKAGE.name
|
|
|
|
const INDEX = fs.readFileSync('./app/www/index.html', 'utf8')
|
2017-08-22 01:23:48 +00:00
|
|
|
|
|
|
|
let app = restify.createServer({
|
|
|
|
name: APPNAME,
|
2017-08-22 02:59:44 +00:00
|
|
|
version: '0.0.1'
|
2017-08-22 01:23:48 +00:00
|
|
|
})
|
|
|
|
|
2017-08-22 02:59:44 +00:00
|
|
|
function createServer () {
|
|
|
|
app.get('/', index)
|
2017-08-22 04:00:24 +00:00
|
|
|
app.get('/frame', rFrame)
|
|
|
|
app.post('/frame', rFrame)
|
|
|
|
app.get('/sequence', () => {})
|
|
|
|
app.post('/sequence', () => {})
|
2017-08-22 03:52:27 +00:00
|
|
|
app.get('/status', rStatus)
|
2017-08-22 02:59:44 +00:00
|
|
|
app.listen(PORT, () => {
|
|
|
|
console.log(`${APPNAME} listening on port ${PORT}!`)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function rFrame (req, res, next) {
|
|
|
|
res.send({})
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
|
|
|
|
function rStatus (req, res, next) {
|
2017-08-22 04:00:24 +00:00
|
|
|
const obj = intval.status()
|
|
|
|
res.send({})
|
2017-08-22 02:59:44 +00:00
|
|
|
return next()
|
|
|
|
}
|
|
|
|
|
2017-08-22 01:11:07 +00:00
|
|
|
function index (req, res, next) {
|
2017-08-22 02:59:44 +00:00
|
|
|
res.end(INDEX)
|
|
|
|
return next()
|
2017-08-22 01:11:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-22 02:59:44 +00:00
|
|
|
function init () {
|
|
|
|
createServer()
|
|
|
|
|
|
|
|
ble.on('data', (str) => {
|
|
|
|
console.log(str)
|
|
|
|
})
|
|
|
|
}
|
2017-08-22 01:11:07 +00:00
|
|
|
|
2017-08-22 02:59:44 +00:00
|
|
|
init()
|