intval3/index.js

64 lines
1.1 KiB
JavaScript
Raw Normal View History

'use strict'
const restify = require('restify')
2017-09-26 03:25:34 +00:00
const log = require('./lib/log')('main')
const fs = require('fs')
const ble = require('./lib/blootstrap')
const intval = require('./lib/intval')
const PACKAGE = require('./package.json')
const PORT = process.env.PORT || 6699
const APPNAME = PACKAGE.name
const INDEXPATH = './app/www/index.html'
let app = restify.createServer({
name: APPNAME,
version: '0.0.1'
})
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', () => {})
app.get('/status', rStatus)
app.listen(PORT, () => {
2017-09-26 03:25:34 +00:00
log.info('server', { name : APPNAME, port : PORT })
})
}
function rFrame (req, res, next) {
2017-09-26 03:25:34 +00:00
intval.frame()
res.send({})
return next()
}
function rStatus (req, res, next) {
2017-08-22 04:00:24 +00:00
const obj = intval.status()
2017-09-26 03:25:34 +00:00
res.send(obj)
return next()
}
function index (req, res, next) {
fs.readFile(INDEXPATH, (err, data) => {
if (err) {
return next(err)
}
res.end(data)
next()
}, 'utf8')
}
function init () {
createServer()
ble.on('data', (str) => {
console.log(str)
})
}
init()